[llvm] [InstCombine] Offset both sides of an equality icmp (PR #134086)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 27 08:36:18 PDT 2025
================
@@ -5808,6 +5808,134 @@ static Instruction *foldICmpPow2Test(ICmpInst &I,
return nullptr;
}
+/// Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
+using OffsetOp = std::pair<Instruction::BinaryOps, Value *>;
+static void collectOffsetOp(Value *V, SmallVectorImpl<OffsetOp> &Offsets,
+ bool AllowRecursion) {
+ Instruction *Inst = dyn_cast<Instruction>(V);
+ if (!Inst)
+ return;
+
+ switch (Inst->getOpcode()) {
+ case Instruction::Add: {
+ Constant *C;
+ if (match(Inst->getOperand(1), m_ImmConstant(C)) &&
+ !C->containsUndefOrPoisonElement()) {
+ if (Constant *NegC = ConstantExpr::getNeg(C))
+ Offsets.emplace_back(Instruction::Add, NegC);
+ }
----------------
nikic wrote:
Would generating `sub, rhs` instead of specializing to constant RHS buy us anything?
https://github.com/llvm/llvm-project/pull/134086
More information about the llvm-commits
mailing list