[PATCH] D157304: [ValueTracking] If `OrZero` is set, look through `trunc` in `isKnownToBePowerOfTwo`
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 9 12:45:46 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbab8058d3b00: [ValueTracking] If `OrZero` is set, look through `trunc` in… (authored by goldstein.w.n).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157304/new/
https://reviews.llvm.org/D157304
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
@@ -36,7 +36,8 @@
; CHECK-SAME: (i16 [[X:%.*]], i8 [[Y:%.*]]) {
; CHECK-NEXT: [[XP2:%.*]] = shl i16 4, [[X]]
; CHECK-NEXT: [[XX:%.*]] = trunc i16 [[XP2]] to i8
-; CHECK-NEXT: [[R:%.*]] = urem i8 [[Y]], [[XX]]
+; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[XX]], -1
+; CHECK-NEXT: [[R:%.*]] = and i8 [[TMP1]], [[Y]]
; CHECK-NEXT: ret i8 [[R]]
;
%xp2 = shl i16 4, %x
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -2036,6 +2036,8 @@
switch (I->getOpcode()) {
case Instruction::ZExt:
return isKnownToBeAPowerOfTwo(I->getOperand(0), OrZero, Depth, Q);
+ case Instruction::Trunc:
+ return OrZero && isKnownToBeAPowerOfTwo(I->getOperand(0), OrZero, Depth, Q);
case Instruction::Shl:
if (OrZero || Q.IIQ.hasNoUnsignedWrap(I) || Q.IIQ.hasNoSignedWrap(I))
return isKnownToBeAPowerOfTwo(I->getOperand(0), OrZero, Depth, Q);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157304.548742.patch
Type: text/x-patch
Size: 1257 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230809/d0772eb6/attachment.bin>
More information about the llvm-commits
mailing list