[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
Wed Aug 9 12:46:13 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfbb40df2bff0: [ValueTracking] In `isKnownToBeAPowerOfTwo` an `i1` value is always true if… (authored by goldstein.w.n).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157310/new/
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
@@ -619,8 +619,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
@@ -634,8 +633,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
@@ -2009,6 +2009,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.548747.patch
Type: text/x-patch
Size: 1595 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230809/e16db5f5/attachment.bin>
More information about the llvm-commits
mailing list