[PATCH] D149413: [ValueTracking] Add logic for `isKnownNonZero(usub.sat X, Y)`
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 27 23:20:32 PDT 2023
goldstein.w.n created this revision.
goldstein.w.n added reviewers: StephenFan, nikic, spatel.
Herald added a subscriber: hiraditya.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
`(usub X, Y) != 0` -> `X u> Y`
Alive2 Link:
https://alive2.llvm.org/ce/z/o29DK4
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149413
Files:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Analysis/ValueTracking/known-non-zero.ll
Index: llvm/test/Analysis/ValueTracking/known-non-zero.ll
===================================================================
--- llvm/test/Analysis/ValueTracking/known-non-zero.ll
+++ 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)
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ 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))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149413.517797.patch
Type: text/x-patch
Size: 1945 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230428/32de2a30/attachment.bin>
More information about the llvm-commits
mailing list