[llvm] bab8058 - [ValueTracking] If `OrZero` is set, look through `trunc` in `isKnownToBePowerOfTwo`
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 9 12:45:41 PDT 2023
Author: Noah Goldstein
Date: 2023-08-09T14:42:54-05:00
New Revision: bab8058d3b00b341e74ce91dc84c2c73b0ceb261
URL: https://github.com/llvm/llvm-project/commit/bab8058d3b00b341e74ce91dc84c2c73b0ceb261
DIFF: https://github.com/llvm/llvm-project/commit/bab8058d3b00b341e74ce91dc84c2c73b0ceb261.diff
LOG: [ValueTracking] If `OrZero` is set, look through `trunc` in `isKnownToBePowerOfTwo`
Just move coverage.
Proof: https://alive2.llvm.org/ce/z/H37tVX
Differential Revision: https://reviews.llvm.org/D157304
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Analysis/ValueTracking/known-power-of-two.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 652b1e8b653a41..794c1100a017be 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2036,6 +2036,8 @@ bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero, unsigned Depth,
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);
diff --git a/llvm/test/Analysis/ValueTracking/known-power-of-two.ll b/llvm/test/Analysis/ValueTracking/known-power-of-two.ll
index 90dec875fb90eb..1936e009e44568 100644
--- a/llvm/test/Analysis/ValueTracking/known-power-of-two.ll
+++ b/llvm/test/Analysis/ValueTracking/known-power-of-two.ll
@@ -36,7 +36,8 @@ define i8 @trunc_is_pow2_or_zero(i16 %x, i8 %y) {
; 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
More information about the llvm-commits
mailing list