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

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

Open kmpeng opened this issue 1 year ago • 0 comments

Follow up to #99114.

The codegen for faceforward looks something like

faceforward(p1, p2, p3) ->
  dResult       = dot(p2, p3)
  cmpResult  = fcmp dResult, 0.0
  subResult   = fsub -0.0 p1
  select(cmpResult, p1, subResult)

which means we can pattern match in SPIRVCombine.td and SPIRVPreLegalizerCombiner.cpp to

select(
    fcmp(
        dot(p2, p3), 
        0),
    p1,
    0 - p1) 

This would allow us to change select(fcmp(dot(p2, p3), 0), p1, 0 - p1) to faceforward(p1, p2, p3) so that we use the right SPIR-V extension function.

kmpeng avatar Apr 24 '25 22:04 kmpeng