Skip to content

Commit b11fe33

Browse files
authored
[RISCV] Correct the cost model for the i1 reduce.add and reduce.or. (#122349)
reduce.add uses the same sequence as reduce.xor. reduce.or should use vmor not vmxor.
1 parent b1893ca commit b11fe33

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ RISCVTTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
15481548
getRISCVInstructionCost(RISCV::VCPOP_M, LT.second, CostKind) +
15491549
getCmpSelInstrCost(Instruction::ICmp, ElementTy, ElementTy,
15501550
CmpInst::ICMP_EQ, CostKind);
1551-
} else if (ISD == ISD::XOR) {
1551+
} else if (ISD == ISD::XOR || ISD == ISD::ADD) {
15521552
// Example sequences:
15531553
// vsetvli a0, zero, e8, mf8, ta, ma
15541554
// vmxor.mm v8, v0, v8 ; needed every time type is split
@@ -1558,13 +1558,14 @@ RISCVTTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
15581558
getRISCVInstructionCost(RISCV::VMXOR_MM, LT.second, CostKind) +
15591559
getRISCVInstructionCost(RISCV::VCPOP_M, LT.second, CostKind) + 1;
15601560
} else {
1561+
assert(ISD == ISD::OR);
15611562
// Example sequences:
15621563
// vsetvli a0, zero, e8, mf8, ta, ma
1563-
// vmxor.mm v8, v9, v8 ; needed every time type is split
1564+
// vmor.mm v8, v9, v8 ; needed every time type is split
15641565
// vcpop.m a0, v0
15651566
// snez a0, a0
15661567
return (LT.first - 1) *
1567-
getRISCVInstructionCost(RISCV::VMXOR_MM, LT.second, CostKind) +
1568+
getRISCVInstructionCost(RISCV::VMOR_MM, LT.second, CostKind) +
15681569
getRISCVInstructionCost(RISCV::VCPOP_M, LT.second, CostKind) +
15691570
getCmpSelInstrCost(Instruction::ICmp, ElementTy, ElementTy,
15701571
CmpInst::ICMP_NE, CostKind);

0 commit comments

Comments
 (0)