[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 11:29:23 PDT 2023
goldstein.w.n updated this revision to Diff 548698.
goldstein.w.n added a comment.
Rebase
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.548698.patch
Type: text/x-patch
Size: 1257 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230809/f8b2d668/attachment.bin>
More information about the llvm-commits
mailing list