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

Andreas Jonson via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 5 08:17:28 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() &&
----------------
andjo403 wrote:

the samesign is used to convert unsigned pred to signed in getPreferredSignedPredicate so think that this suggestion is good reduces some duplication

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


More information about the llvm-commits mailing list