[llvm] 8272546 - [HLSL][SPIRV] Fix `faceforward` pattern matcher logic (#183630)

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 11:47:45 PST 2026


Author: Kaitlin Peng
Date: 2026-03-03T11:47:41-08:00
New Revision: 8272546f6910e78f255830d9592c6926d93be04c

URL: https://github.com/llvm/llvm-project/commit/8272546f6910e78f255830d9592c6926d93be04c
DIFF: https://github.com/llvm/llvm-project/commit/8272546f6910e78f255830d9592c6926d93be04c.diff

LOG: [HLSL][SPIRV] Fix `faceforward` pattern matcher logic (#183630)

Fixes a logic issue in the `faceforward` pattern matcher in
`SPIRVCombinerHelper.cpp`.
Previously when `mi_match` failed, we would still go through the nested
`Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_UGT` check. It was
possible that whatever garbage was in Pred could randomly pass this
check and make us continue through the code. This change fixes that
logic issue by returning false as soon as `mi_match` fails.

Likely fixes #177803. Can't confirm since it seems another change has
obscured the crash.

Added: 
    

Modified: 
    llvm/lib/Target/SPIRV/SPIRVCombinerHelper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/SPIRV/SPIRVCombinerHelper.cpp b/llvm/lib/Target/SPIRV/SPIRVCombinerHelper.cpp
index 7ea8ec00440de..e8b2f8204f73e 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCombinerHelper.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCombinerHelper.cpp
@@ -91,12 +91,12 @@ bool SPIRVCombinerHelper::matchSelectToFaceForward(MachineInstr &MI) const {
   Register DotReg, CondZeroReg;
   CmpInst::Predicate Pred;
   if (!mi_match(CondReg, MRI,
-                m_GFCmp(m_Pred(Pred), m_Reg(DotReg), m_Reg(CondZeroReg))) ||
-      !(Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_ULT)) {
-    if (!(Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_UGT))
-      return false;
+                m_GFCmp(m_Pred(Pred), m_Reg(DotReg), m_Reg(CondZeroReg))))
+    return false;
+  if (Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_UGT)
     std::swap(DotReg, CondZeroReg);
-  }
+  else if (!(Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_ULT))
+    return false;
 
   // Check if FCMP is a comparison between a dot product and 0.
   MachineInstr *DotInstr = MRI.getVRegDef(DotReg);


        


More information about the llvm-commits mailing list