[llvm] [RISCV][CostModel] Updates reduction and shuffle cost (PR #77342)
Shih-Po Hung via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 10 07:26:06 PST 2024
================
@@ -1392,20 +1426,58 @@ RISCVTTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
return BaseT::getArithmeticReductionCost(Opcode, Ty, FMF, CostKind);
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty);
- if (Ty->getElementType()->isIntegerTy(1))
+ SmallVector<unsigned, 3> Opcodes;
+ Type *ElementTy = Ty->getElementType();
+ if (ElementTy->isIntegerTy(1)) {
// vcpop sequences, see vreduction-mask.ll
- return (LT.first - 1) + (ISD == ISD::AND ? 3 : 2);
+ if (ISD == ISD::AND) {
+ Opcodes = {RISCV::VMNAND_MM, RISCV::VCPOP_M};
----------------
arcbbb wrote:
You've made a good observation about the capacity and size here.
For clarity, in the context of SmallVector the capacity of Opcodes is 3, and the current size is 2 here.
ArrayRef is constructed from the size of the SmallVector, so I think the extra capacity will not be used.
I was based on the logic in
```
/// Construct an ArrayRef from a SmallVector. This is templated in order to
/// avoid instantiating SmallVectorTemplateCommon<T> whenever we
/// copy-construct an ArrayRef.
template<typename U>
/*implicit*/ ArrayRef(const SmallVectorTemplateCommon<T, U> &Vec)
: Data(Vec.data()), Length(Vec.size()) {
}
```
https://github.com/llvm/llvm-project/pull/77342
More information about the llvm-commits
mailing list