diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -2903,9 +2903,18 @@ return true; break; case Intrinsic::ssub_sat: - return isNonZeroSub(DemandedElts, Depth, Q, BitWidth, II->getArgOperand(0), - II->getArgOperand(1)); - + return isNonZeroSub(DemandedElts, Depth, Q, BitWidth, + II->getArgOperand(0), II->getArgOperand(1)); + case Intrinsic::usub_sat: { + KnownBits XKnown = + computeKnownBits(II->getArgOperand(0), DemandedElts, Depth, Q); + if (XKnown.isUnknown()) + return false; + KnownBits YKnown = + computeKnownBits(II->getArgOperand(1), DemandedElts, Depth, Q); + std::optional<bool> ugt = KnownBits::ugt(XKnown, YKnown); + return ugt && *ugt; + } case Intrinsic::uadd_sat: if (isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q) || isKnownNonZero(II->getArgOperand(1), DemandedElts, Depth, Q)) diff --git a/llvm/test/Analysis/ValueTracking/known-non-zero.ll b/llvm/test/Analysis/ValueTracking/known-non-zero.ll --- a/llvm/test/Analysis/ValueTracking/known-non-zero.ll +++ b/llvm/test/Analysis/ValueTracking/known-non-zero.ll @@ -815,11 +815,7 @@ ; CHECK-LABEL: @usub_sat_nonzero( ; CHECK-NEXT: [[Y_ULT_31:%.*]] = icmp ult i8 [[YY:%.*]], 31 ; CHECK-NEXT: call void @llvm.assume(i1 [[Y_ULT_31]]) -; CHECK-NEXT: [[XO:%.*]] = or i8 [[XX:%.*]], 34 -; CHECK-NEXT: [[X:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[XO]], i8 [[YY]]) -; CHECK-NEXT: [[Z:%.*]] = or i8 [[X]], [[IND:%.*]] -; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[Z]], 0 -; CHECK-NEXT: ret i1 [[R]] +; CHECK-NEXT: ret i1 false ; %y_ult_31 = icmp ult i8 %yy, 31 call void @llvm.assume(i1 %y_ult_31)