Skip to content

Commit 0700e64

Browse files
committed
Recommit "[RISCV] Refine cost on Min/Max reduction (llvm#79402)"
This is recommitted as the test and fix for llvm.vector.reduce.fmaximum/fminimum are covered in llvm#80553 and llvm#80697
1 parent 3cb0241 commit 0700e64

File tree

5 files changed

+266
-237
lines changed

5 files changed

+266
-237
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,13 +1047,42 @@ RISCVTTIImpl::getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty,
10471047
}
10481048

10491049
// IR Reduction is composed by two vmv and one rvv reduction instruction.
1050-
InstructionCost BaseCost = 2;
1051-
1052-
if (CostKind == TTI::TCK_CodeSize)
1053-
return (LT.first - 1) + BaseCost;
1054-
1055-
unsigned VL = getEstimatedVLFor(Ty);
1056-
return (LT.first - 1) + BaseCost + Log2_32_Ceil(VL);
1050+
unsigned SplitOp;
1051+
SmallVector<unsigned, 3> Opcodes;
1052+
switch (IID) {
1053+
default:
1054+
llvm_unreachable("Unsupported intrinsic");
1055+
case Intrinsic::smax:
1056+
SplitOp = RISCV::VMAX_VV;
1057+
Opcodes = {RISCV::VMV_S_X, RISCV::VREDMAX_VS, RISCV::VMV_X_S};
1058+
break;
1059+
case Intrinsic::smin:
1060+
SplitOp = RISCV::VMIN_VV;
1061+
Opcodes = {RISCV::VMV_S_X, RISCV::VREDMIN_VS, RISCV::VMV_X_S};
1062+
break;
1063+
case Intrinsic::umax:
1064+
SplitOp = RISCV::VMAXU_VV;
1065+
Opcodes = {RISCV::VMV_S_X, RISCV::VREDMAXU_VS, RISCV::VMV_X_S};
1066+
break;
1067+
case Intrinsic::umin:
1068+
SplitOp = RISCV::VMINU_VV;
1069+
Opcodes = {RISCV::VMV_S_X, RISCV::VREDMINU_VS, RISCV::VMV_X_S};
1070+
break;
1071+
case Intrinsic::maxnum:
1072+
SplitOp = RISCV::VFMAX_VV;
1073+
Opcodes = {RISCV::VFMV_S_F, RISCV::VFREDMAX_VS, RISCV::VFMV_F_S};
1074+
break;
1075+
case Intrinsic::minnum:
1076+
SplitOp = RISCV::VFMIN_VV;
1077+
Opcodes = {RISCV::VFMV_S_F, RISCV::VFREDMIN_VS, RISCV::VFMV_F_S};
1078+
break;
1079+
}
1080+
// Add a cost for data larger than LMUL8
1081+
InstructionCost SplitCost =
1082+
(LT.first > 1) ? (LT.first - 1) *
1083+
getRISCVInstructionCost(SplitOp, LT.second, CostKind)
1084+
: 0;
1085+
return SplitCost + getRISCVInstructionCost(Opcodes, LT.second, CostKind);
10571086
}
10581087

10591088
InstructionCost

0 commit comments

Comments
 (0)