llvm / llvm/llvm-project

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

Open
#214,884 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backend:SPIR-V
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing patterns in SPIRVCombine.td and the matching logic in SPIRVCombinerHelper.cpp, along with the follow-up context from #213097. Implement recognition of the shown fadd/fmul/fsub shape so SPIR-V emits the lerp GL extension again; done means the generic lowering is combined back to lerp.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.