[llvm] [InstCombine] Fold comparisons of llvm.usub.sat result with its LHS (PR #214108)
Haram Jeong via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 10 01:48:00 PDT 2026
================
@@ -7811,6 +7740,24 @@ Instruction *InstCombinerImpl::foldICmpCommutative(CmpPredicate Pred,
}
const SimplifyQuery Q = SQ.getWithInstruction(&CxtI);
+
+ {
+ Value *Y;
+ // For Y != 0:
+ // usub.sat(X, Y) == X --> X == 0
+ // usub.sat(X, Y) != X --> X != 0
+ // usub.sat(X, Y) < X --> X != 0
+ if (match(Op0, m_Intrinsic<Intrinsic::usub_sat>(m_Specific(Op1),
+ m_Value(Y))) &&
+ (CmpInst::isEquality(Pred) || Pred == ICmpInst::ICMP_ULT) &&
+ isKnownNonZero(Y, Q)) {
+ ICmpInst::Predicate NewPred =
+ CmpInst::isEquality(Pred) ? Pred.dropSameSign() : ICmpInst::ICMP_NE;
----------------
haramj wrote:
Added a samesign equality test to cover this.
https://github.com/llvm/llvm-project/pull/214108
More information about the llvm-commits
mailing list