[PATCH] D157308: [ValueTracking] Add support for `mul` in `isKnownToBeAPowerOfTwo`
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 9 11:30:14 PDT 2023
goldstein.w.n updated this revision to Diff 548702.
goldstein.w.n added a comment.
Rebase
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157308/new/
https://reviews.llvm.org/D157308
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
@@ -379,7 +379,8 @@
; CHECK-NEXT: [[XP2:%.*]] = shl i16 4, [[X]]
; CHECK-NEXT: [[ZP2:%.*]] = shl i16 2, [[Z]]
; CHECK-NEXT: [[XX:%.*]] = mul i16 [[XP2]], [[ZP2]]
-; CHECK-NEXT: [[R:%.*]] = urem i16 [[Y]], [[XX]]
+; CHECK-NEXT: [[TMP1:%.*]] = add i16 [[XX]], -1
+; CHECK-NEXT: [[R:%.*]] = and i16 [[TMP1]], [[Y]]
; CHECK-NEXT: ret i16 [[R]]
;
%xp2 = shl i16 4, %x
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -2050,6 +2050,10 @@
if (Q.IIQ.isExact(cast<BinaryOperator>(I)))
return isKnownToBeAPowerOfTwo(I->getOperand(0), OrZero, Depth, Q);
return false;
+ case Instruction::Mul:
+ return OrZero &&
+ isKnownToBeAPowerOfTwo(I->getOperand(1), OrZero, Depth, Q) &&
+ isKnownToBeAPowerOfTwo(I->getOperand(0), OrZero, Depth, Q);
case Instruction::And:
if (OrZero) {
// A power of two and'd with anything is a power of two or zero.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157308.548702.patch
Type: text/x-patch
Size: 1307 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230809/382c9d47/attachment.bin>
More information about the llvm-commits
mailing list