[llvm] [InstCombine] Fold `icmp samesign u{gt/lt} (X +nsw C2), C` -> `icmp s{gt/lt} X, (C - C2)` (PR #169960)
Tirthankar Mazumder via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 5 08:04:30 PST 2025
================
@@ -3183,6 +3183,18 @@ Instruction *InstCombinerImpl::foldICmpAddConstant(ICmpInst &Cmp,
return new ICmpInst(Pred, X, ConstantInt::get(Ty, NewC));
}
+ CmpInst::Predicate ChosenPred = Pred.getPreferredSignedPredicate();
+
+ if (Pred.hasSameSign() && Add->hasNoSignedWrap() &&
----------------
wermos wrote:
It seems to me that the `samesign` flag is required for the transformation to be correct. See [this](https://alive2.llvm.org/ce/z/WzjQ5M) Alive2 link for a counterexample.
Since the `samesign` seems to be required, I don't know if this modification should be done.
https://github.com/llvm/llvm-project/pull/169960
More information about the llvm-commits
mailing list