[llvm] [InstCombine] Remove checks for -1 and 0 in saturated unsigned add (NFC) (PR #153047)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 11 09:21:42 PDT 2025
https://github.com/AZero13 created https://github.com/llvm/llvm-project/pull/153047
>=u 0 is uneeded to check because this is always true (InstSimplify will deal with it) and >u -1 is always false, so they will never come up anyway.
>From 605da03750bcc03fb9f48b7b5c3c5f0b50121ebe Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Mon, 11 Aug 2025 12:21:27 -0400
Subject: [PATCH] [InstCombine] Remove checks for -1 and 0 in saturated
unsigned add (NFC)
>=u 0 is uneeded to check because this is always true (InstSimplify will deal with it) and >u -1 is always false, so they will never come up anyway.
---
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index eb4332fbc0959..3a3b7f3063f95 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -1054,21 +1054,17 @@ static Value *canonicalizeSaturatedAdd(ICmpInst *Cmp, Value *TVal, Value *FVal,
ConstantInt::get(Cmp0->getType(), *C));
}
- // Negative one does not work here because X u> -1 ? -1, X + -1 is not a
- // saturated add.
if (Pred == ICmpInst::ICMP_UGT &&
match(FVal, m_Add(m_Specific(Cmp0), m_APIntAllowPoison(C))) &&
- match(Cmp1, m_SpecificIntAllowPoison(~*C - 1)) && !C->isAllOnes()) {
+ match(Cmp1, m_SpecificIntAllowPoison(~*C - 1))) {
// (X u> ~C - 1) ? -1 : (X + C) --> uadd.sat(X, C)
return Builder.CreateBinaryIntrinsic(Intrinsic::uadd_sat, Cmp0,
ConstantInt::get(Cmp0->getType(), *C));
}
- // Zero does not work here because X u>= 0 ? -1 : X -> is always -1, which is
- // not a saturated add.
if (Pred == ICmpInst::ICMP_UGE &&
match(FVal, m_Add(m_Specific(Cmp0), m_APIntAllowPoison(C))) &&
- match(Cmp1, m_SpecificIntAllowPoison(-*C)) && !C->isZero()) {
+ match(Cmp1, m_SpecificIntAllowPoison(-*C))) {
// (X u >= -C) ? -1 : (X + C) --> uadd.sat(X, C)
return Builder.CreateBinaryIntrinsic(Intrinsic::uadd_sat, Cmp0,
ConstantInt::get(Cmp0->getType(), *C));
More information about the llvm-commits
mailing list