[llvm] [InstCombine] Rewrite (A + C2) == C -> A == (C - C2) if cmp folds. (PR #222151)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 15 05:52:59 PDT 2026
================
@@ -3766,8 +3767,18 @@ Instruction *InstCombinerImpl::foldICmpBinOpEqualityWithConstant(
// (A + C2) != C --> A != (C - C2)
// TODO: Remove the one-use limitation? See discussion in D58633.
if (Constant *C2 = dyn_cast<Constant>(BOp1)) {
+ Constant *NewRHS = ConstantExpr::getSub(RHS, C2);
if (BO->hasOneUse())
- return new ICmpInst(Pred, BOp0, ConstantExpr::getSub(RHS, C2));
+ return new ICmpInst(Pred, BOp0, NewRHS);
+
+ // If the add has other uses, the rewrite is still profitable if the
+ // compare folds away.
+ if (!AC.assumptionsFor(BOp0).empty() || !DC.conditionsFor(BOp0).empty()) {
+ Constant *NewRHS = ConstantExpr::getSub(RHS, C2);
+ if (Value *V = simplifyICmpInst(Pred, BOp0, NewRHS,
----------------
fhahn wrote:
Any thoughts on the InstSimplify version? Compile-time wise `mafft 33066M 33081M (+0.05%)` is the one that sticks out. I tried to reduce compile-time impact, but couldn't find anything really to shave off.
https://github.com/llvm/llvm-project/pull/222151
More information about the llvm-commits
mailing list