[llvm] [InstCombine] Fold comparisons of llvm.usub.sat result with its LHS (PR #214108)

Andreas Jonson via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 5 13:00:01 PDT 2026


================
@@ -3953,6 +3953,36 @@ Instruction *InstCombinerImpl::foldICmpEqIntrinsicWithConstant(
 }
 
 /// Fold an icmp with LLVM intrinsics
+static Instruction *
+foldICmpUSubSatWithLHS(ICmpInst &Cmp) {
+  // For C != 0:
+  // usub.sat(X, C) == X  -->  X == 0
+  // usub.sat(X, C) <  X  -->  X != 0
+  ICmpInst::Predicate Pred = Cmp.getPredicate();
+  if (Pred != ICmpInst::ICMP_EQ && Pred != ICmpInst::ICMP_ULT)
----------------
andjo403 wrote:

also works for ICMP_NE and ICMP_UGT
  // usub.sat(X, C) != X  -->  X != 0
  // X > usub.sat(X, C)   -->  X != 0

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


More information about the llvm-commits mailing list