[llvm] [InstCombine] Improve coverage of `foldSelectValueEquivalence` (PR #88298)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 5 20:06:21 PDT 2024


================
@@ -1308,11 +1310,52 @@ Instruction *InstCombinerImpl::foldSelectValueEquivalence(SelectInst &Sel,
       if (match(V, m_ImmConstant()))
         return replaceOperand(Sel, Swapped ? 2 : 1, V);
 
-      // If NewOp is a constant and OldOp is not replace iff NewOp doesn't
-      // contain and undef/poison elements.
-      if (match(NewOp, m_ImmConstant()) &&
-          isGuaranteedNotToBeUndefOrPoison(NewOp, SQ.AC, &Sel, &DT))
+      // We can't do any further replacement if NewOp may be undef/poison.
+      if (!isGuaranteedNotToBeUndefOrPoison(NewOp, SQ.AC, &Sel, &DT))
+        return nullptr;
+
+      // If NewOp is a constant, replace.
+      if (match(NewOp, m_ImmConstant()))
+        return replaceOperand(Sel, Swapped ? 2 : 1, V);
+
+      // If we simplified the TrueArm -> NewOp then replace.
+      // This handles things like `select`/`min`/`max`/`or`/`and`/etc...
+      if (NewOp == V)
----------------
dtcxzyw wrote:

Can you do some stress tests (e.g., csmith) for 3-4 days (~10 million test cases on a 128C server)?


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


More information about the llvm-commits mailing list