Skip to content

Commit f95eaae

Browse files
committed
[SLP][REVEC] Fix cost model for getBuildVectorCost with FixedVectorType
ScalarTy. BoUpSLP::gather always use CreateInsertVector for FixedVectorType ScalarTy.
1 parent 3332da6 commit f95eaae

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9198,10 +9198,18 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
91989198
bool NeedShuffle =
91999199
count(VL, *It) > 1 &&
92009200
(VL.front() != *It || !all_of(VL.drop_front(), IsaPred<UndefValue>));
9201-
if (!NeedShuffle)
9201+
if (!NeedShuffle) {
9202+
if (isa<FixedVectorType>(ScalarTy)) {
9203+
assert(SLPReVec && "FixedVectorType is not expected.");
9204+
return TTI.getShuffleCost(
9205+
TTI::SK_InsertSubvector, VecTy, {}, CostKind,
9206+
std::distance(VL.begin(), It) * getNumElements(ScalarTy),
9207+
cast<FixedVectorType>(ScalarTy));
9208+
}
92029209
return TTI.getVectorInstrCost(Instruction::InsertElement, VecTy,
92039210
CostKind, std::distance(VL.begin(), It),
92049211
PoisonValue::get(VecTy), *It);
9212+
}
92059213

92069214
SmallVector<int> ShuffleMask(VL.size(), PoisonMaskElem);
92079215
transform(VL, ShuffleMask.begin(), [](Value *V) {

llvm/test/Transforms/SLPVectorizer/RISCV/revec-getGatherCost.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ declare <4 x float> @llvm.fmuladd.v4f32(<4 x float>, <4 x float>, <4 x float>)
4747
; YAML: Function: test2
4848
; YAML: Args:
4949
; YAML: - String: 'Stores SLP vectorized with cost '
50-
; YAML: - Cost: '15'
50+
; YAML: - Cost: '16'
5151
; YAML: - String: ' and with tree size '
5252
; YAML: - TreeSize: '5'
5353

0 commit comments

Comments
 (0)