[llvm] [InstCombine] Simplify and/or of icmp eq with op replacement (PR #70335)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 27 13:23:34 PDT 2023
================
@@ -2025,6 +2025,52 @@ static Value *simplifyAndOrOfCmps(const SimplifyQuery &Q, Value *Op0,
return nullptr;
}
+static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
+ const SimplifyQuery &Q,
+ bool AllowRefinement,
+ SmallVectorImpl<Instruction *> *DropFlags,
+ unsigned MaxRecurse);
+
+static Value *simplifyAndOrWithICmpEq(unsigned Opcode, Value *Op0, Value *Op1,
+ const SimplifyQuery &Q,
+ unsigned MaxRecurse) {
+ assert((Opcode == Instruction::And || Opcode == Instruction::Or) &&
+ "Must be and/or");
+ ICmpInst::Predicate Pred;
+ Value *A, *B;
+ if (!match(Op0, m_ICmp(Pred, m_Value(A), m_Value(B))) ||
+ !ICmpInst::isEquality(Pred) || !MaxRecurse--)
+ return nullptr;
+
+ auto Simplify = [&](Value *Res) -> Value * {
+ // and (icmp eq a, b), x implies (a==b) inside x.
+ // or (icmp ne a, b), x implies (a==b) inside x.
----------------
nikic wrote:
If we had a way to say "simplify x under the assumption that a != b", I would expect that to be beneficial. But we can only do this for equalities right now, as in that case we can just replace operands.
I think we need some generic way to say "evaluate this predicate under the assumption that v has range CR" -- some of @dtcxzyw's recent PRs go in that direction, but I feel like there must be a more generic solution to this, which integrates with existing range propagation logic, instead of reimplementing it in parts. This seems like something that LVI/CVP should be doing, but I don't see a good way to integrate it there.
https://github.com/llvm/llvm-project/pull/70335
More information about the llvm-commits
mailing list