[llvm] [ConstraintElim] Handle (X | Y) >s -1 as X >s -1 && Y >s -1. (PR #209743)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 16 04:11:49 PDT 2026


================
@@ -1980,6 +1980,30 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT, LoopInfo &LI,
                                      DFSInStack);
       }
 
+      // (X | Y) >=s 0 implies X >=s 0 and Y >=s 0, because the sign bit of an
+      // OR is the OR of the operand sign bits. Look through this
+      // canonicalization by InstCombine. disjunct so it is available to the
+      // solver.
+      if ((Pred == CmpInst::ICMP_SGE && match(B, m_Zero())) ||
+          (Pred == CmpInst::ICMP_SGT && match(B, m_AllOnes()))) {
+        SmallVector<Value *> OrWorklist = {A};
+        SmallPtrSet<Value *, 4> SeenOr;
+        Value *X, *Y;
+        while (!OrWorklist.empty()) {
+          Value *Cur = OrWorklist.pop_back_val();
+          if (!match(Cur, m_Or(m_Value(X), m_Value(Y))))
----------------
fhahn wrote:

PR available here https://github.com/llvm/llvm-project/pull/210033

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


More information about the llvm-commits mailing list