Skip to content

Commit 5c43d52

Browse files
committed
[RISCV][TTI] Count whole vector register move and match codegen result.
1 parent 22cb3db commit 5c43d52

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,21 @@ RISCVTTIImpl::isMultipleInsertSubvector(VectorType *Tp, ArrayRef<int> Mask,
366366
if (Skip)
367367
continue;
368368
InstructionCost Cost = 0;
369-
FixedVectorType *SubTp = FixedVectorType::get(
370-
cast<FixedVectorType>(Tp)->getElementType(), SubVecSize);
369+
unsigned NumSlides = Log2_32(E / SubVecSize);
371370
// The cost of extraction from a subvector is 0 if the index is 0.
372-
for (unsigned I = 0; I != E; I += SubVecSize)
373-
Cost +=
374-
getShuffleCost(TTI::SK_InsertSubvector, Tp, {}, CostKind, I, SubTp);
371+
for (unsigned I = 0; I != NumSlides; ++I) {
372+
unsigned InsertIndex = SubVecSize * (1 << I);
373+
FixedVectorType *SubTp = FixedVectorType::get(
374+
cast<FixedVectorType>(Tp)->getElementType(), InsertIndex);
375+
FixedVectorType *DesTp =
376+
FixedVectorType::getDoubleElementsVectorType(SubTp);
377+
std::pair<InstructionCost, MVT> DesLT = getTypeLegalizationCost(DesTp);
378+
// Add the cost of whole vector register move because the destination
379+
// vector register group for vslideup cannot overlap the source.
380+
Cost += DesLT.first * TLI->getLMULCost(DesLT.second);
381+
Cost += getShuffleCost(TTI::SK_InsertSubvector, DesTp, {}, CostKind,
382+
InsertIndex, SubTp);
383+
}
375384
return Cost;
376385
}
377386
return InstructionCost::getInvalid();

llvm/test/Analysis/CostModel/RISCV/fixed-vector-insert-subvector.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
define void @test() {
55
; CHECK-LABEL: 'test'
66
; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %0 = shufflevector <8 x float> poison, <8 x float> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
7-
; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %1 = shufflevector <4 x i16> poison, <4 x i16> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 0, i32 1, i32 2, i32 3, i32 0, i32 1, i32 2, i32 3, i32 0, i32 1, i32 2, i32 3>
7+
; CHECK-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %1 = shufflevector <4 x i16> poison, <4 x i16> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 0, i32 1, i32 2, i32 3, i32 0, i32 1, i32 2, i32 3, i32 0, i32 1, i32 2, i32 3>
88
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %2 = shufflevector <4 x float> poison, <4 x float> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 0, i32 1, i32 2, i32 3>
99
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %3 = shufflevector <2 x i1> poison, <2 x i1> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
1010
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void

0 commit comments

Comments
 (0)