@@ -231,6 +231,20 @@ static bool isValidElementType(Type *Ty) {
231
231
!Ty->isPPC_FP128Ty();
232
232
}
233
233
234
+ /// Returns the type of the given value/instruction \p V. If it is store,
235
+ /// returns the type of its value operand, for Cmp - the types of the compare
236
+ /// operands and for insertelement - the type os the inserted operand.
237
+ /// Otherwise, just the type of the value is returned.
238
+ template <typename T> static Type *getValueType(T *V) {
239
+ if (auto *SI = dyn_cast<StoreInst>(V))
240
+ return SI->getValueOperand()->getType();
241
+ if (auto *CI = dyn_cast<CmpInst>(V))
242
+ return CI->getOperand(0)->getType();
243
+ if (auto *IE = dyn_cast<InsertElementInst>(V))
244
+ return IE->getOperand(1)->getType();
245
+ return V->getType();
246
+ }
247
+
234
248
/// \returns the number of elements for Ty.
235
249
static unsigned getNumElements(Type *Ty) {
236
250
assert(!isa<ScalableVectorType>(Ty) &&
@@ -6987,20 +7001,13 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
6987
7001
}
6988
7002
6989
7003
// Don't handle vectors.
6990
- if (!SLPReVec && S.OpValue->getType( )->isVectorTy() &&
7004
+ if (!SLPReVec && getValueType( S.OpValue)->isVectorTy() &&
6991
7005
!isa<InsertElementInst>(S.OpValue)) {
6992
7006
LLVM_DEBUG(dbgs() << "SLP: Gathering due to vector type.\n");
6993
7007
newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx);
6994
7008
return;
6995
7009
}
6996
7010
6997
- if (StoreInst *SI = dyn_cast<StoreInst>(S.OpValue))
6998
- if (!SLPReVec && SI->getValueOperand()->getType()->isVectorTy()) {
6999
- LLVM_DEBUG(dbgs() << "SLP: Gathering due to store vector type.\n");
7000
- newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx);
7001
- return;
7002
- }
7003
-
7004
7011
// If all of the operands are identical or constant we have a simple solution.
7005
7012
// If we deal with insert/extract instructions, they all must have constant
7006
7013
// indices, otherwise we should gather them, not try to vectorize.
@@ -9433,15 +9440,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
9433
9440
SmallPtrSetImpl<Value *> &CheckedExtracts) {
9434
9441
ArrayRef<Value *> VL = E->Scalars;
9435
9442
9436
- Type *ScalarTy = VL[0]->getType();
9437
- if (!E->isGather()) {
9438
- if (auto *SI = dyn_cast<StoreInst>(VL[0]))
9439
- ScalarTy = SI->getValueOperand()->getType();
9440
- else if (auto *CI = dyn_cast<CmpInst>(VL[0]))
9441
- ScalarTy = CI->getOperand(0)->getType();
9442
- else if (auto *IE = dyn_cast<InsertElementInst>(VL[0]))
9443
- ScalarTy = IE->getOperand(1)->getType();
9444
- }
9443
+ Type *ScalarTy = getValueType(VL[0]);
9445
9444
if (!isValidElementType(ScalarTy))
9446
9445
return InstructionCost::getInvalid();
9447
9446
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
@@ -13132,11 +13131,9 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
13132
13131
}
13133
13132
13134
13133
Value *V = E->Scalars.front();
13135
- Type *ScalarTy = V->getType();
13136
- if (auto *Store = dyn_cast<StoreInst>(V))
13137
- ScalarTy = Store->getValueOperand()->getType();
13138
- else if (auto *IE = dyn_cast<InsertElementInst>(V))
13139
- ScalarTy = IE->getOperand(1)->getType();
13134
+ Type *ScalarTy = getValueType(V);
13135
+ if (isa<CmpInst>(V))
13136
+ ScalarTy = V->getType();
13140
13137
auto It = MinBWs.find(E);
13141
13138
if (It != MinBWs.end()) {
13142
13139
auto *VecTy = dyn_cast<FixedVectorType>(ScalarTy);
@@ -16937,9 +16934,7 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
16937
16934
bool Changed = false;
16938
16935
bool CandidateFound = false;
16939
16936
InstructionCost MinCost = SLPCostThreshold.getValue();
16940
- Type *ScalarTy = VL[0]->getType();
16941
- if (auto *IE = dyn_cast<InsertElementInst>(VL[0]))
16942
- ScalarTy = IE->getOperand(1)->getType();
16937
+ Type *ScalarTy = getValueType(VL[0]);
16943
16938
16944
16939
unsigned NextInst = 0, MaxInst = VL.size();
16945
16940
for (unsigned VF = MaxVF; NextInst + 1 < MaxInst && VF >= MinVF; VF /= 2) {
@@ -19057,7 +19052,7 @@ bool SLPVectorizerPass::vectorizeCmpInsts(iterator_range<ItT> CmpInsts,
19057
19052
19058
19053
SmallVector<Value *> Vals;
19059
19054
for (Instruction *V : CmpInsts)
19060
- if (!R.isDeleted(V) && isValidElementType(V->getType( )))
19055
+ if (!R.isDeleted(V) && isValidElementType(getValueType(V )))
19061
19056
Vals.push_back(V);
19062
19057
if (Vals.size() <= 1)
19063
19058
return Changed;
0 commit comments