[llvm] [ConstraintElim] Extend `checkOrAndOpImpliedByOther` to handle and/or expr trees. (PR #117123)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 21 04:06:40 PST 2024
================
@@ -1511,22 +1508,40 @@ static bool checkOrAndOpImpliedByOther(
if (OtherOpIdx != 0 && isa<SelectInst>(JoinOp))
return false;
- if (!match(JoinOp->getOperand(OtherOpIdx),
- m_ICmp(Pred, m_Value(A), m_Value(B))))
- return false;
-
- // For OR, check if the negated condition implies CmpToCheck.
- bool IsOr = match(JoinOp, m_LogicalOr());
- if (IsOr)
- Pred = CmpInst::getInversePredicate(Pred);
-
// Optimistically add fact from first condition.
unsigned OldSize = DFSInStack.size();
- Info.addFact(Pred, A, B, CB.NumIn, CB.NumOut, DFSInStack);
+ auto InfoRestorer = make_scope_exit([&]() {
+ // Remove entries again.
+ while (OldSize < DFSInStack.size()) {
+ StackEntry E = DFSInStack.back();
+ removeEntryFromStack(E, Info, ReproducerModule, ReproducerCondStack,
+ DFSInStack);
+ }
+ });
+ // For OR, check if the negated condition implies CmpToCheck.
+ bool IsOr = match(JoinOp, m_LogicalOr());
+ SmallVector<Value *, 4> Worklist({JoinOp->getOperand(OtherOpIdx)});
+ while (!Worklist.empty()) {
+ Value *Val = Worklist.pop_back_val();
+ Value *LHS, *RHS;
+ ICmpInst::Predicate Pred;
+ if (match(Val, m_ICmp(Pred, m_Value(LHS), m_Value(RHS)))) {
+ if (IsOr)
+ Pred = CmpInst::getInversePredicate(Pred);
+ Info.addFact(Pred, LHS, RHS, CB.NumIn, CB.NumOut, DFSInStack);
----------------
fhahn wrote:
```suggestion
// Optimistically add fact from the other compares in the AND/OR.
Info.addFact(Pred, LHS, RHS, CB.NumIn, CB.NumOut, DFSInStack);
```
https://github.com/llvm/llvm-project/pull/117123
More information about the llvm-commits
mailing list