aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorNoah Goldstein <goldstein.w.n@gmail.com>2024-04-03 15:33:55 -0500
committerNoah Goldstein <goldstein.w.n@gmail.com>2024-04-10 13:13:42 -0500
commit87528bfefbb50ed6560b9b8482fc7c9f86ca34cd (patch)
treed2d301ae7c4d769119b1f4bb0f9b370951340e24 /llvm/lib/Analysis/ValueTracking.cpp
parentc1d3f39ae98535777c957aab3611d2abc97b2815 (diff)
downloadllvm-87528bfefbb50ed6560b9b8482fc7c9f86ca34cd.zip
llvm-87528bfefbb50ed6560b9b8482fc7c9f86ca34cd.tar.gz
llvm-87528bfefbb50ed6560b9b8482fc7c9f86ca34cd.tar.bz2
[ValueTracking] Add support for `shufflevector` in `isKnownNonZero`
Shuffles don't modify the data, so if all elements that end up in the destination are non-zero the result is non-zero. Closes #87702
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 5ef1969..b3029f4 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2777,6 +2777,21 @@ static bool isKnownNonZeroFromOperator(const Operator *I,
}
}
break;
+ case Instruction::ShuffleVector: {
+ auto *Shuf = dyn_cast<ShuffleVectorInst>(I);
+ if (!Shuf)
+ break;
+ APInt DemandedLHS, DemandedRHS;
+ // For undef elements, we don't know anything about the common state of
+ // the shuffle result.
+ if (!getShuffleDemandedElts(Shuf, DemandedElts, DemandedLHS, DemandedRHS))
+ break;
+ // If demanded elements for both vecs are non-zero, the shuffle is non-zero.
+ return (DemandedRHS.isZero() ||
+ isKnownNonZero(Shuf->getOperand(1), DemandedRHS, Depth, Q)) &&
+ (DemandedLHS.isZero() ||
+ isKnownNonZero(Shuf->getOperand(0), DemandedLHS, Depth, Q));
+ }
case Instruction::Freeze:
return isKnownNonZero(I->getOperand(0), Depth, Q) &&
isGuaranteedNotToBePoison(I->getOperand(0), Q.AC, Q.CxtI, Q.DT,