aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorNoah Goldstein <goldstein.w.n@gmail.com>2023-02-18 13:36:06 -0600
committerNoah Goldstein <goldstein.w.n@gmail.com>2023-02-18 13:45:15 -0600
commit3bd38f66398303eb375085dc2681c94c7169f273 (patch)
treedf32300ec1adc463606273d91d37aa9235c975a1 /llvm/lib/Analysis/ValueTracking.cpp
parente0ce87509b18957fc82dd5b1aa5ad50e81412294 (diff)
downloadllvm-3bd38f66398303eb375085dc2681c94c7169f273.zip
llvm-3bd38f66398303eb375085dc2681c94c7169f273.tar.gz
llvm-3bd38f66398303eb375085dc2681c94c7169f273.tar.bz2
[ValueTracking] Add cases for additional ops in `isKnownNonZero`
Add cases for the following ops: - 0-X -- https://alive2.llvm.org/ce/z/6C75Li - bitreverse(X) -- https://alive2.llvm.org/ce/z/SGG1q9 - bswap(X) -- https://alive2.llvm.org/ce/z/p7pzwh - ctpop(X) -- https://alive2.llvm.org/ce/z/c5y3BC - abs(X) -- https://alive2.llvm.org/ce/z/yxXGz_ https://alive2.llvm.org/ce/z/rSRg4K - uadd_sat(X, Y) -- https://alive2.llvm.org/ce/z/Zw-y4W https://alive2.llvm.org/ce/z/2NRqRz https://alive2.llvm.org/ce/z/M1OpF8 Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D142828
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 536d880..bf3b4c9 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2607,6 +2607,12 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
Q.DL.getTypeSizeInBits(I->getType()).getFixedValue())
return isKnownNonZero(I->getOperand(0), Depth, Q);
break;
+ case Instruction::Sub:
+ if (auto *C = dyn_cast<Constant>(I->getOperand(0)))
+ if (C->isNullValue() &&
+ isKnownNonZero(I->getOperand(1), DemandedElts, Depth, Q))
+ return true;
+ break;
case Instruction::Or:
// X | Y != 0 if X != 0 or Y != 0.
return isKnownNonZero(I->getOperand(0), DemandedElts, Depth, Q) ||
@@ -2751,8 +2757,26 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
isGuaranteedNotToBePoison(I->getOperand(0), Q.AC, Q.CxtI, Q.DT,
Depth);
case Instruction::Call:
- if (cast<CallInst>(I)->getIntrinsicID() == Intrinsic::vscale)
- return true;
+ if (auto *II = dyn_cast<IntrinsicInst>(I)) {
+ switch (II->getIntrinsicID()) {
+ case Intrinsic::abs:
+ case Intrinsic::bitreverse:
+ case Intrinsic::bswap:
+ case Intrinsic::ctpop:
+ if (isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q))
+ return true;
+ break;
+ case Intrinsic::uadd_sat:
+ if (isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q) ||
+ isKnownNonZero(II->getArgOperand(1), DemandedElts, Depth, Q))
+ return true;
+ break;
+ case Intrinsic::vscale:
+ return true;
+ default:
+ break;
+ }
+ }
break;
}