aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorNoah Goldstein <goldstein.w.n@gmail.com>2023-10-05 21:16:34 -0500
committerNoah Goldstein <goldstein.w.n@gmail.com>2023-10-12 16:05:19 -0500
commitdfda65c89272eb90c0377f6c15ad134fc902dab6 (patch)
treec267b1287b59b318ea314ee837649ff129c9aac5 /llvm/lib/Analysis/ValueTracking.cpp
parent9427fce6778c8d01a0519cd0382a0ae6a75b2d35 (diff)
downloadllvm-dfda65c89272eb90c0377f6c15ad134fc902dab6.zip
llvm-dfda65c89272eb90c0377f6c15ad134fc902dab6.tar.gz
llvm-dfda65c89272eb90c0377f6c15ad134fc902dab6.tar.bz2
[ValueTracking] Add support for non-splat vecs in cmpExcludesZero
Just a small QOL change.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 11b3975..2b0bbe6 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -567,11 +567,24 @@ static bool cmpExcludesZero(CmpInst::Predicate Pred, const Value *RHS) {
// All other predicates - rely on generic ConstantRange handling.
const APInt *C;
- if (!match(RHS, m_APInt(C)))
+ auto Zero = APInt::getZero(RHS->getType()->getScalarSizeInBits());
+ if (match(RHS, m_APInt(C))) {
+ ConstantRange TrueValues = ConstantRange::makeExactICmpRegion(Pred, *C);
+ return !TrueValues.contains(Zero);
+ }
+
+ auto *VC = dyn_cast<ConstantDataVector>(RHS);
+ if (VC == nullptr)
return false;
- ConstantRange TrueValues = ConstantRange::makeExactICmpRegion(Pred, *C);
- return !TrueValues.contains(APInt::getZero(C->getBitWidth()));
+ for (unsigned ElemIdx = 0, NElem = VC->getNumElements(); ElemIdx < NElem;
+ ++ElemIdx) {
+ ConstantRange TrueValues = ConstantRange::makeExactICmpRegion(
+ Pred, VC->getElementAsAPInt(ElemIdx));
+ if (TrueValues.contains(Zero))
+ return false;
+ }
+ return true;
}
static bool isKnownNonZeroFromAssume(const Value *V, const SimplifyQuery &Q) {