Skip to content

Commit 806bbab

Browse files
committed
[RISCV][TTI] Model the cost of extractelt when it cannot using vmv + vslide.
This patch implement the cost when the size of the vector need to split into multiple groups and the index exceed single vector group. Under this situation, we need the store the vector to stack and load the target element. After this patch, the cost of extract element will close to the generated assembly.
1 parent a4c3683 commit 806bbab

File tree

2 files changed

+61
-44
lines changed

2 files changed

+61
-44
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,23 @@ InstructionCost RISCVTTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val,
19451945
// TODO: should we count these special vsetvlis?
19461946
BaseCost = Opcode == Instruction::InsertElement ? 3 : 4;
19471947
}
1948+
1949+
// When the vector need to split into multiple register groups and the index
1950+
// exceed single vector resgister group, we need to extract the element via
1951+
// stack.
1952+
if (Opcode == Instruction::ExtractElement && LT.first > 1 &&
1953+
((Index == -1U) || (Index > LT.second.getVectorMinNumElements() &&
1954+
LT.second.isScalableVector()))) {
1955+
Type *ScalarType = Val->getScalarType();
1956+
Align VecAlign = DL.getPrefTypeAlign(Val);
1957+
Align SclAlign = DL.getPrefTypeAlign(ScalarType);
1958+
// Store all split vectors into stack and load the target element.
1959+
return LT.first *
1960+
getMemoryOpCost(Instruction::Store, Val, VecAlign, 0, CostKind) +
1961+
getMemoryOpCost(Instruction::Load, ScalarType, SclAlign, 0,
1962+
CostKind);
1963+
}
1964+
19481965
return BaseCost + SlideCost;
19491966
}
19501967

0 commit comments

Comments
 (0)