[llvm] [ConstraintElim] Check if second op implies first for And. (PR #75750)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 17 13:18:24 PST 2023


================
@@ -1365,16 +1365,24 @@ removeEntryFromStack(const StackEntry &E, ConstraintInfo &Info,
     ReproducerCondStack.pop_back();
 }
 
-/// Check if the first condition for an AND implies the second.
-static bool checkAndSecondOpImpliedByFirst(
-    FactOrCheck &CB, ConstraintInfo &Info, Module *ReproducerModule,
-    SmallVectorImpl<ReproducerEntry> &ReproducerCondStack,
-    SmallVectorImpl<StackEntry> &DFSInStack) {
+/// Check if either the first condition of an AND is implied by the second or
+/// vice versa.
+static bool
+checkAndOpImpliedByOther(FactOrCheck &CB, ConstraintInfo &Info,
+                         Module *ReproducerModule,
+                         SmallVectorImpl<ReproducerEntry> &ReproducerCondStack,
+                         SmallVectorImpl<StackEntry> &DFSInStack) {
 
   CmpInst::Predicate Pred;
   Value *A, *B;
   Instruction *And = CB.getContextInst();
-  if (!match(And->getOperand(0), m_ICmp(Pred, m_Value(A), m_Value(B))))
+  CmpInst *CmpToCheck = cast<CmpInst>(CB.getInstructionToSimplify());
+  unsigned OtherOpIdx = And->getOperand(0) == CmpToCheck ? 1 : 0;
+
+  if (OtherOpIdx != 0 && isa<SelectInst>(And))
----------------
nikic wrote:

Is this due to a poison-propagation issue?

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


More information about the llvm-commits mailing list