llvm-project
llvm-project copied to clipboard
[SPIRV] Add PreLegalizer pattern matching for `normalize` GL extension
Follow-up to #128043.
Following the normalize implementation move, SPIR-V now lowers normalize as a sequence of dot/rsqrt/insertelement/shufflevector/fmul instructions instead of the GL extension:
normalize(x) ->
d = dot x, x
r = rsqrt d
splat = shufflevector(insertelement(poison, r, 0), poison, zeroinitializer)
fmul x, splat
We can pattern match this in SPIRVCombine.td and SPIRVPreLegalizerCombiner.cpp to
fmul(
x,
shufflevector(
insertelement(poison,
rsqrt(dot(x, x)),
0),
poison,
zeroinitializer))
which would allow us to change this sequence back into normalize(x) so that SPIR-V emits the GL extension again.
Going to take a different approach to emit the GL extension since pattern matching normalize is quite complicated.
Update: still going to go with pattern matching, but it will be done in #128043 and not as a follow-up.