[PATCH] D157310: [ValueTracking] In `isKnownToBeAPowerOfTwo` an `i1` value is always true if `OrZero` is set
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 7 10:49:25 PDT 2023
goldstein.w.n created this revision.
goldstein.w.n added reviewers: nikic, Allen.
Herald added subscribers: StephenFan, 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.
This is trivially true.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157310
Files:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Analysis/ValueTracking/known-power-of-two.ll
Index: llvm/test/Analysis/ValueTracking/known-power-of-two.ll
===================================================================
--- llvm/test/Analysis/ValueTracking/known-power-of-two.ll
+++ llvm/test/Analysis/ValueTracking/known-power-of-two.ll
@@ -585,8 +585,7 @@
; CHECK-LABEL: define i16 @i1_is_pow2_or_zero
; CHECK-SAME: (i1 [[X:%.*]], i16 [[Y:%.*]]) {
; CHECK-NEXT: [[XX:%.*]] = zext i1 [[X]] to i16
-; CHECK-NEXT: [[YY:%.*]] = xor i16 [[XX]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = call i16 @llvm.umax.i16(i16 [[YY]], i16 [[Y]])
+; CHECK-NEXT: [[R:%.*]] = or i16 [[XX]], [[Y]]
; CHECK-NEXT: ret i16 [[R]]
;
%xx = zext i1 %x to i16
@@ -600,8 +599,7 @@
; CHECK-SAME: (i1 [[X:%.*]], i16 [[Y0:%.*]], i16 [[Z:%.*]]) {
; CHECK-NEXT: [[XX:%.*]] = zext i1 [[X]] to i16
; CHECK-NEXT: [[Y:%.*]] = or i16 [[Y0]], [[Z]]
-; CHECK-NEXT: [[YY:%.*]] = xor i16 [[Y]], [[XX]]
-; CHECK-NEXT: [[R:%.*]] = call i16 @llvm.umax.i16(i16 [[YY]], i16 [[Y]])
+; CHECK-NEXT: [[R:%.*]] = or i16 [[Y]], [[XX]]
; CHECK-NEXT: ret i16 [[R]]
;
%xx = zext i1 %x to i16
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -2016,6 +2016,10 @@
if (isa<Constant>(V))
return OrZero ? match(V, m_Power2OrZero()) : match(V, m_Power2());
+ // i1 is by definition a power of 2 or zero.
+ if (OrZero && V->getType()->getScalarSizeInBits() == 1)
+ return true;
+
auto *I = dyn_cast<Instruction>(V);
if (!I)
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157310.547857.patch
Type: text/x-patch
Size: 1595 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230807/2feda95b/attachment.bin>
More information about the llvm-commits
mailing list