aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 563929a..64594d9 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -166,10 +166,11 @@ static const Instruction *safeCxtI(const Value *V1, const Value *V2, const Instr
static bool getShuffleDemandedElts(const ShuffleVectorInst *Shuf,
const APInt &DemandedElts,
APInt &DemandedLHS, APInt &DemandedRHS) {
- // The length of scalable vectors is unknown at compile time, thus we
- // cannot check their values
- if (isa<ScalableVectorType>(Shuf->getType()))
- return false;
+ if (isa<ScalableVectorType>(Shuf->getType())) {
+ assert(DemandedElts == APInt(1,1));
+ DemandedLHS = DemandedRHS = DemandedElts;
+ return true;
+ }
int NumElts =
cast<FixedVectorType>(Shuf->getOperand(0)->getType())->getNumElements();
@@ -206,13 +207,9 @@ static void computeKnownBits(const Value *V, const APInt &DemandedElts,
static void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth,
const Query &Q) {
- // FIXME: We currently have no way to represent the DemandedElts of a scalable
- // vector
- if (isa<ScalableVectorType>(V->getType())) {
- Known.resetAll();
- return;
- }
-
+ // Since the number of lanes in a scalable vector is unknown at compile time,
+ // we track one bit which is implicitly broadcast to all lanes. This means
+ // that all lanes in a scalable vector are considered demanded.
auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
APInt DemandedElts =
FVTy ? APInt::getAllOnes(FVTy->getNumElements()) : APInt(1, 1);
@@ -1238,7 +1235,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
// Look through a cast from narrow vector elements to wider type.
// Examples: v4i32 -> v2i64, v3i8 -> v24
unsigned SubBitWidth = SrcVecTy->getScalarSizeInBits();
- if (BitWidth % SubBitWidth == 0) {
+ if (BitWidth % SubBitWidth == 0 && !isa<ScalableVectorType>(I->getType())) {
// Known bits are automatically intersected across demanded elements of a
// vector. So for example, if a bit is computed as known zero, it must be
// zero across all demanded elements of the vector.
@@ -1832,6 +1829,10 @@ static void computeKnownBitsFromOperator(const Operator *I,
break;
}
case Instruction::InsertElement: {
+ if (isa<ScalableVectorType>(I->getType())) {
+ Known.resetAll();
+ return;
+ }
const Value *Vec = I->getOperand(0);
const Value *Elt = I->getOperand(1);
auto *CIdx = dyn_cast<ConstantInt>(I->getOperand(2));
@@ -1948,9 +1949,8 @@ KnownBits computeKnownBits(const Value *V, unsigned Depth, const Query &Q) {
/// for all of the demanded elements in the vector specified by DemandedElts.
void computeKnownBits(const Value *V, const APInt &DemandedElts,
KnownBits &Known, unsigned Depth, const Query &Q) {
- if (!DemandedElts || isa<ScalableVectorType>(V->getType())) {
- // No demanded elts or V is a scalable vector, better to assume we don't
- // know anything.
+ if (!DemandedElts) {
+ // No demanded elts, better to assume we don't know anything.
Known.resetAll();
return;
}
@@ -1971,7 +1971,7 @@ void computeKnownBits(const Value *V, const APInt &DemandedElts,
"DemandedElt width should equal the fixed vector number of elements");
} else {
assert(DemandedElts == APInt(1, 1) &&
- "DemandedElt width should be 1 for scalars");
+ "DemandedElt width should be 1 for scalars or scalable vectors");
}
Type *ScalarTy = Ty->getScalarType();
@@ -1998,6 +1998,7 @@ void computeKnownBits(const Value *V, const APInt &DemandedElts,
// Handle a constant vector by taking the intersection of the known bits of
// each element.
if (const ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(V)) {
+ assert(!isa<ScalableVectorType>(V->getType()));
// We know that CDV must be a vector of integers. Take the intersection of
// each element.
Known.Zero.setAllBits(); Known.One.setAllBits();
@@ -2012,6 +2013,7 @@ void computeKnownBits(const Value *V, const APInt &DemandedElts,
}
if (const auto *CV = dyn_cast<ConstantVector>(V)) {
+ assert(!isa<ScalableVectorType>(V->getType()));
// We know that CV must be a vector of integers. Take the intersection of
// each element.
Known.Zero.setAllBits(); Known.One.setAllBits();