[SPIRV] Add PreLegalizer pattern matching for `lerp` GL extension
Follow-up to #213097.
Following the lerp implementation move, SPIR-V now lowers lerp as a generic fsub+fmul+fadd instead of the GL extension:
lerp(x, y, s) ->
sub = fsub y, x
mul = fmul s, sub
fadd x, mul
We can pattern match this in SPIRVCombine.td and SPIRVCombinerHelper.cpp to
fadd(
x,
fmul(s,
fsub(y, x)))
which would allow us to change fadd(x, fmul(s, fsub(y, x))) back into lerp(x, y, s) so that SPIR-V emits the GL extension again.
If nobody has been working on it, perhaps I can help?
@shri-acha No one's working on it, so that would be great, thanks!
@shri-acha Did you still plan to work on this? If not, I'm going to assign the issue to myself
@kmpeng Oops, yes, I've worked on it a little bit already, I'll push raise a PR maybe today or tomorrow, sorry about the delay 😅.
@shri-acha No worries and no rush! I was just looking through issues I could work on next. Will be assigning this one to you then
Please see this comment and follow-up thread in https://github.com/llvm/llvm-project/pull/227126 . I would love to recommend to be careful with pattern-matching in SPIR-V backend as SPIR-V is not the final ISA and do it only if it's required for legalization.
Also please double check if llvm opt does this optimization for you already.
@shri-acha - see #229194 (and comment above from @MrSidims) - we should probably put this issue on hold until we've figured out what the right next steps are. Feel free to unassign yourself while we figure this out.