[llvm] [RISCV][CostModel] Correct the cost of some reductions (PR #118072)
Shih-Po Hung via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 1 17:53:05 PST 2024
================
@@ -1534,6 +1534,13 @@ RISCVTTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
getRISCVInstructionCost(Opcodes, LT.second, CostKind) +
getCmpSelInstrCost(Instruction::ICmp, ElementTy, ElementTy,
CmpInst::ICMP_EQ, CostKind);
+ } else if (ISD == ISD::XOR) {
+ // Example sequences:
+ // vsetvli a0, zero, e8, mf8, ta, ma
+ // vcpop.m a0, v0
+ // andi a0, a0, 1
+ Opcodes = {RISCV::VCPOP_M};
+ return LT.first + getRISCVInstructionCost(Opcodes, LT.second, CostKind);
----------------
arcbbb wrote:
`(LT.first - 1)` first appeared in this [commit](https://github.com/llvm/llvm-project/commit/536095a27c17e2f30765111f57d36c0ee9e211c7).
It seems to be used to calculate the additional cost when the LMUL exceeds 8.
For example,
```
define zeroext i1 @vreduce_and_nxv1i1(<vscale x 128 x i1> %v) {
; vmand.mm v8, v0, v8 // addtional cost when LMUL exceeds 8.
; vmnot.m v8, v8
; vcpop.m a0, v8
; seqz a0, a0
%red = call i1 @llvm.vector.reduce.and.nxv128i1(<vscale x 128 x i1> %v)
ret i1 %red
}
```
https://github.com/llvm/llvm-project/pull/118072
More information about the llvm-commits
mailing list