Skip to content

Commit efd4576

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 acaa5fa commit efd4576

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
@@ -2003,6 +2003,23 @@ InstructionCost RISCVTTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val,
20032003
// TODO: should we count these special vsetvlis?
20042004
BaseCost = Opcode == Instruction::InsertElement ? 3 : 4;
20052005
}
2006+
2007+
// When the vector need to split into multiple register groups and the index
2008+
// exceed single vector resgister group, we need to extract the element via
2009+
// stack.
2010+
if (Opcode == Instruction::ExtractElement && LT.first > 1 &&
2011+
((Index == -1U) || (Index > LT.second.getVectorMinNumElements() &&
2012+
LT.second.isScalableVector()))) {
2013+
Type *ScalarType = Val->getScalarType();
2014+
Align VecAlign = DL.getPrefTypeAlign(Val);
2015+
Align SclAlign = DL.getPrefTypeAlign(ScalarType);
2016+
// Store all split vectors into stack and load the target element.
2017+
return LT.first *
2018+
getMemoryOpCost(Instruction::Store, Val, VecAlign, 0, CostKind) +
2019+
getMemoryOpCost(Instruction::Load, ScalarType, SclAlign, 0,
2020+
CostKind);
2021+
}
2022+
20062023
return BaseCost + SlideCost;
20072024
}
20082025

0 commit comments

Comments
 (0)