[clang] [llvm] [SPIRV] Add PreLegalizer instCombine for `faceforward` (PR #139959)

Farzon Lotfi via cfe-commits cfe-commits at lists.llvm.org
Thu May 15 13:48:56 PDT 2025


================
@@ -0,0 +1,63 @@
+# RUN: llc -verify-machineinstrs -O0 -mtriple spirv-unknown-unknown -run-pass=spirv-prelegalizer-combiner %s -o - | FileCheck %s
+# REQUIRES: asserts
+---
+name:            faceforward_instcombine_float
+tracksRegLiveness: true
+legalized: true
+body:             |
+  bb.1.entry:
+    ; CHECK-LABEL: name: faceforward_instcombine_float
+    ; CHECK-NOT: %9:_(s32) = G_FCONSTANT float 0.000000e+00
+    ; CHECK-NOT: %8:_(s32) = G_FMUL %1:fid, %2:fid
+    ; CHECK-NOT: %10:_(s1) = G_FCMP floatpred(olt), %8:_(s32), %9:_
+    ; CHECK-NOT: %11:_(s32) = G_FNEG %0:fid
+    ; CHECK-NOT: %12:id(s32) = G_SELECT %10:_(s1), %0:fid, %11:_
+    ; CHECK: %10:id(s32) = G_INTRINSIC intrinsic(@llvm.spv.faceforward), %2(s32), %3(s32), %4(s32)
----------------
farzonl wrote:

This is probably my fault, I don't think I did enought in the distance ticket to test it properly.  But in length to distance we were replacing one intrinsic with another. In this case we are creating an intrinsic out of nothing should we be wrapping the intrinsic in `G_INTRINSIC_W_SIDE_EFFECTS`?

https://github.com/llvm/llvm-project/pull/139959


More information about the cfe-commits mailing list