[llvm] [InstCombine] Fold `icmp samesign u{gt/lt} (X +nsw C2), C` -> `icmp s{gt/lt} X, (C - C2)` (PR #169960)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 5 08:12:35 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() &&
----------------
dtcxzyw wrote:

This flag is checked inside getPreferredSignedPredicate.

https://github.com/llvm/llvm-project/pull/169960


More information about the llvm-commits mailing list