[llvm] [InstSimplify] Extend icmp-of-add simplification to sle/sgt/sge (PR #168900)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 20 09:55:31 PST 2025
================
@@ -3261,20 +3261,22 @@ static Value *simplifyICmpWithBinOpOnLHS(CmpPredicate Pred, BinaryOperator *LBO,
// If only one of the icmp's operands has NSW flags, try to prove that:
//
-// icmp slt (x + C1), (x +nsw C2)
+// icmp slt/sgt/sle/sge (x + C1), (x +nsw C2)
//
// is equivalent to:
//
-// icmp slt C1, C2
+// icmp slt/sgt/sle/sge C1, C2
//
// which is true if x + C2 has the NSW flags set and:
-// *) C1 < C2 && C1 >= 0, or
-// *) C2 < C1 && C1 <= 0.
+// *) C1 <= C2 && C1 >= 0, or
+// *) C2 <= C1 && C1 <= 0.
//
static bool trySimplifyICmpWithAdds(CmpPredicate Pred, Value *LHS, Value *RHS,
const InstrInfoQuery &IIQ) {
- // TODO: only support icmp slt for now.
- if (Pred != CmpInst::ICMP_SLT || !IIQ.UseInstrInfo)
+ // TODO: support other predicates.
+ if ((Pred != CmpInst::ICMP_SLT && Pred != CmpInst::ICMP_SGT &&
----------------
dtcxzyw wrote:
Use `!ICmpInst::isSigned`
https://github.com/llvm/llvm-project/pull/168900
More information about the llvm-commits
mailing list