Skip to content

Commit 91c156b

Browse files
committed
use VF to instead of VecTy->getNumElements()
When ScalarTy is FixedVectorType, VecTy->getNumElements() is different from ScalarTy is NOT FixedVectorType. However, VF is same.
1 parent cb8acd6 commit 91c156b

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5243,10 +5243,9 @@ BoUpSLP::canVectorizeLoads(ArrayRef<Value *> VL, const Value *VL0,
52435243
Instruction::GetElementPtr, CostKind, ScalarTy, VecTy);
52445244
// Estimate the cost of masked gather GEP. If not a splat, roughly
52455245
// estimate as a buildvector, otherwise estimate as splat.
5246-
APInt DemandedElts = APInt::getAllOnes(VecTy->getNumElements());
5246+
APInt DemandedElts = APInt::getAllOnes(Sz);
52475247
VectorType *PtrVecTy =
5248-
getWidenedType(PointerOps.front()->getType()->getScalarType(),
5249-
VecTy->getNumElements());
5248+
getWidenedType(PointerOps.front()->getType()->getScalarType(), Sz);
52505249
if (static_cast<unsigned>(count_if(
52515250
PointerOps, IsaPred<GetElementPtrInst>)) < PointerOps.size() - 1 ||
52525251
any_of(PointerOps, [&](Value *V) {
@@ -5257,9 +5256,9 @@ BoUpSLP::canVectorizeLoads(ArrayRef<Value *> VL, const Value *VL0,
52575256
PtrVecTy, DemandedElts, /*Insert=*/true, /*Extract=*/false, CostKind);
52585257
else
52595258
VectorGEPCost +=
5260-
TTI.getScalarizationOverhead(
5261-
PtrVecTy, APInt::getOneBitSet(VecTy->getNumElements(), 0),
5262-
/*Insert=*/true, /*Extract=*/false, CostKind) +
5259+
TTI.getScalarizationOverhead(PtrVecTy, APInt::getOneBitSet(Sz, 0),
5260+
/*Insert=*/true, /*Extract=*/false,
5261+
CostKind) +
52635262
::getShuffleCost(TTI, TTI::SK_Broadcast, PtrVecTy, {}, CostKind);
52645263
// The cost of scalar loads.
52655264
InstructionCost ScalarLoadsCost =
@@ -5340,7 +5339,6 @@ BoUpSLP::canVectorizeLoads(ArrayRef<Value *> VL, const Value *VL0,
53405339
VecLdCost +=
53415340
TTI.getInstructionCost(cast<Instruction>(VL[Idx]), CostKind);
53425341
}
5343-
unsigned ScalarTyNumElements = getNumElements(ScalarTy);
53445342
auto *SubVecTy = getWidenedType(ScalarTy, VF);
53455343
for (auto [I, LS] : enumerate(States)) {
53465344
auto *LI0 = cast<LoadInst>(VL[I * VF]);
@@ -5366,8 +5364,7 @@ BoUpSLP::canVectorizeLoads(ArrayRef<Value *> VL, const Value *VL0,
53665364
else
53675365
VectorGEPCost +=
53685366
getScalarizationOverhead(
5369-
TTI, ScalarTy, SubVecTy,
5370-
APInt::getOneBitSet(ScalarTyNumElements * VF, 0),
5367+
TTI, ScalarTy, SubVecTy, APInt::getOneBitSet(VF, 0),
53715368
/*Insert=*/true, /*Extract=*/false, CostKind) +
53725369
::getShuffleCost(TTI, TTI::SK_Broadcast, SubVecTy, {},
53735370
CostKind);
@@ -9969,7 +9966,7 @@ void BoUpSLP::reorderGatherNode(TreeEntry &TE) {
99699966
? TTI::SK_PermuteTwoSrc
99709967
: TTI::SK_PermuteSingleSrc,
99719968
VecTy, ReorderMask);
9972-
DemandedElts = APInt::getAllOnes(VecTy->getNumElements());
9969+
DemandedElts = APInt::getAllOnes(TE.Scalars.size());
99739970
ReorderMask.assign(Sz, PoisonMaskElem);
99749971
for (unsigned I : seq<unsigned>(Sz)) {
99759972
Value *V = TE.getOrdered(I);

0 commit comments

Comments
 (0)