Skip to content

Commit f6fc19a

Browse files
committed
Fix opcode for ICmp and ordered reduction cost
1 parent a69645a commit f6fc19a

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,18 +1434,25 @@ RISCVTTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
14341434
Opcodes = {RISCV::VMNAND_MM, RISCV::VCPOP_M};
14351435
return (LT.first - 1) +
14361436
getRISCVInstructionCost(Opcodes, LT.second, CostKind) +
1437-
getCmpSelInstrCost(Instruction::Select, ElementTy, ElementTy,
1437+
getCmpSelInstrCost(Instruction::ICmp, ElementTy, ElementTy,
14381438
CmpInst::ICMP_EQ, CostKind);
14391439
} else {
14401440
Opcodes = {RISCV::VCPOP_M};
14411441
return (LT.first - 1) +
14421442
getRISCVInstructionCost(Opcodes, LT.second, CostKind) +
1443-
getCmpSelInstrCost(Instruction::Select, ElementTy, ElementTy,
1443+
getCmpSelInstrCost(Instruction::ICmp, ElementTy, ElementTy,
14441444
CmpInst::ICMP_NE, CostKind);
14451445
}
14461446
}
14471447

14481448
// IR Reduction is composed by two vmv and one rvv reduction instruction.
1449+
if (TTI::requiresOrderedReduction(FMF)) {
1450+
Opcodes.push_back(RISCV::VFMV_S_F);
1451+
for (unsigned i = 0; i < LT.first.getValue(); i++)
1452+
Opcodes.push_back(RISCV::VFREDOSUM_VS);
1453+
Opcodes.push_back(RISCV::VFMV_F_S);
1454+
return getRISCVInstructionCost(Opcodes, LT.second, CostKind);
1455+
}
14491456
unsigned SplitOp;
14501457
switch (ISD) {
14511458
case ISD::ADD:
@@ -1466,10 +1473,7 @@ RISCVTTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
14661473
break;
14671474
case ISD::FADD:
14681475
SplitOp = RISCV::VFADD_VV;
1469-
if (TTI::requiresOrderedReduction(FMF))
1470-
Opcodes = {RISCV::VFMV_S_F, RISCV::VFREDOSUM_VS, RISCV::VFMV_F_S};
1471-
else
1472-
Opcodes = {RISCV::VFMV_S_F, RISCV::VFREDUSUM_VS, RISCV::VFMV_F_S};
1476+
Opcodes = {RISCV::VFMV_S_F, RISCV::VFREDUSUM_VS, RISCV::VFMV_F_S};
14731477
break;
14741478
}
14751479
// Add a cost for data larger than LMUL8

llvm/test/Analysis/CostModel/RISCV/reduce-fadd.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ define void @reduce_oredered_fadd_float() {
147147
; FP-REDUCE-NEXT: Cost Model: Found an estimated cost of 18 for instruction: %V16 = call float @llvm.vector.reduce.fadd.v16f32(float 0.000000e+00, <16 x float> undef)
148148
; FP-REDUCE-NEXT: Cost Model: Found an estimated cost of 34 for instruction: %v32 = call float @llvm.vector.reduce.fadd.v32f32(float 0.000000e+00, <32 x float> undef)
149149
; FP-REDUCE-NEXT: Cost Model: Found an estimated cost of 66 for instruction: %V64 = call float @llvm.vector.reduce.fadd.v64f32(float 0.000000e+00, <64 x float> undef)
150-
; FP-REDUCE-NEXT: Cost Model: Found an estimated cost of 74 for instruction: %V128 = call float @llvm.vector.reduce.fadd.v128f32(float 0.000000e+00, <128 x float> undef)
150+
; FP-REDUCE-NEXT: Cost Model: Found an estimated cost of 130 for instruction: %V128 = call float @llvm.vector.reduce.fadd.v128f32(float 0.000000e+00, <128 x float> undef)
151151
; FP-REDUCE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
152152
;
153153
; SIZE-LABEL: 'reduce_oredered_fadd_float'
@@ -180,8 +180,8 @@ define void @reduce_oredered_fadd_double() {
180180
; FP-REDUCE-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %V8 = call double @llvm.vector.reduce.fadd.v8f64(double 0.000000e+00, <8 x double> undef)
181181
; FP-REDUCE-NEXT: Cost Model: Found an estimated cost of 18 for instruction: %V16 = call double @llvm.vector.reduce.fadd.v16f64(double 0.000000e+00, <16 x double> undef)
182182
; FP-REDUCE-NEXT: Cost Model: Found an estimated cost of 34 for instruction: %v32 = call double @llvm.vector.reduce.fadd.v32f64(double 0.000000e+00, <32 x double> undef)
183-
; FP-REDUCE-NEXT: Cost Model: Found an estimated cost of 42 for instruction: %V64 = call double @llvm.vector.reduce.fadd.v64f64(double 0.000000e+00, <64 x double> undef)
184-
; FP-REDUCE-NEXT: Cost Model: Found an estimated cost of 58 for instruction: %V128 = call double @llvm.vector.reduce.fadd.v128f64(double 0.000000e+00, <128 x double> undef)
183+
; FP-REDUCE-NEXT: Cost Model: Found an estimated cost of 66 for instruction: %V64 = call double @llvm.vector.reduce.fadd.v64f64(double 0.000000e+00, <64 x double> undef)
184+
; FP-REDUCE-NEXT: Cost Model: Found an estimated cost of 130 for instruction: %V128 = call double @llvm.vector.reduce.fadd.v128f64(double 0.000000e+00, <128 x double> undef)
185185
; FP-REDUCE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
186186
;
187187
; SIZE-LABEL: 'reduce_oredered_fadd_double'

llvm/test/Analysis/CostModel/RISCV/rvv-intrinsics.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,8 @@ define void @reduce_fadd() {
593593
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %28 = call double @llvm.vector.reduce.fadd.nxv4f64(double undef, <vscale x 4 x double> undef)
594594
; CHECK-NEXT: Cost Model: Found an estimated cost of 18 for instruction: %29 = call double @llvm.vp.reduce.fadd.nxv8f64(double undef, <vscale x 8 x double> undef, <vscale x 8 x i1> undef, i32 undef)
595595
; CHECK-NEXT: Cost Model: Found an estimated cost of 18 for instruction: %30 = call double @llvm.vector.reduce.fadd.nxv8f64(double undef, <vscale x 8 x double> undef)
596-
; CHECK-NEXT: Cost Model: Found an estimated cost of 26 for instruction: %31 = call double @llvm.vp.reduce.fadd.nxv16f64(double undef, <vscale x 16 x double> undef, <vscale x 16 x i1> undef, i32 undef)
597-
; CHECK-NEXT: Cost Model: Found an estimated cost of 26 for instruction: %32 = call double @llvm.vector.reduce.fadd.nxv16f64(double undef, <vscale x 16 x double> undef)
596+
; CHECK-NEXT: Cost Model: Found an estimated cost of 34 for instruction: %31 = call double @llvm.vp.reduce.fadd.nxv16f64(double undef, <vscale x 16 x double> undef, <vscale x 16 x i1> undef, i32 undef)
597+
; CHECK-NEXT: Cost Model: Found an estimated cost of 34 for instruction: %32 = call double @llvm.vector.reduce.fadd.nxv16f64(double undef, <vscale x 16 x double> undef)
598598
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
599599
;
600600
call float @llvm.vp.reduce.fadd.v2f32(float undef, <2 x float> undef, <2 x i1> undef, i32 undef)

0 commit comments

Comments
 (0)