[PATCH] D149204: [ValueTracking] Add logic for `add nuw x, y != 0` -> `x != 0 || y != 0`
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 26 15:11:11 PDT 2023
goldstein.w.n updated this revision to Diff 517352.
goldstein.w.n added a comment.
Rebase
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149204/new/
https://reviews.llvm.org/D149204
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
@@ -473,9 +473,7 @@
; CHECK-LABEL: @add_nonzero_nuw(
; CHECK-NEXT: [[X_NZ:%.*]] = icmp ne i8 [[X:%.*]], 0
; CHECK-NEXT: call void @llvm.assume(i1 [[X_NZ]])
-; CHECK-NEXT: [[A:%.*]] = add nuw i8 [[X]], [[Y:%.*]]
-; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[A]], 0
-; CHECK-NEXT: ret i1 [[R]]
+; CHECK-NEXT: ret i1 false
;
%x_nz = icmp ne i8 %x, 0
call void @llvm.assume(i1 %x_nz)
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -2787,6 +2787,14 @@
break;
case Instruction::Add: {
// X + Y.
+
+ // If Add has nuw wrap flag, then if either X or Y is non-zero the result is
+ // non-zero.
+ auto *BO = cast<OverflowingBinaryOperator>(V);
+ if (Q.IIQ.hasNoUnsignedWrap(BO))
+ return isKnownNonZero(I->getOperand(0), DemandedElts, Depth, Q) ||
+ isKnownNonZero(I->getOperand(1), DemandedElts, Depth, Q);
+
KnownBits XKnown =
computeKnownBits(I->getOperand(0), DemandedElts, Depth, Q);
KnownBits YKnown =
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149204.517352.patch
Type: text/x-patch
Size: 1364 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230426/bab070cb/attachment.bin>
More information about the llvm-commits
mailing list