llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[SPIRV] Add PreLegalizer pattern matching for `lerp` GL extension

Open kmpeng opened this issue 3 months ago • 7 comments

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.

kmpeng avatar Aug 07 '26 23:08 kmpeng

If nobody has been working on it, perhaps I can help?

shri-acha avatar Oct 08 '26 02:10 shri-acha

@shri-acha No one's working on it, so that would be great, thanks!

kmpeng avatar Oct 13 '26 03:10 kmpeng

@shri-acha Did you still plan to work on this? If not, I'm going to assign the issue to myself

kmpeng avatar Oct 30 '26 01:10 kmpeng

@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 avatar Oct 30 '26 01:10 shri-acha

@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

kmpeng avatar Oct 30 '26 02:10 kmpeng

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.

MrSidims avatar Nov 02 '26 10:11 MrSidims

@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.

damyanp avatar Nov 02 '26 20:11 damyanp