Skip to content

Commit f3a8112

Browse files
authored
[RISCV][TTI] Scale the cost of ICmp with LMUL (#88235)
Use the Val type to estimate the instruction cost for ICmp.
1 parent 2e26ee9 commit f3a8112

File tree

3 files changed

+174
-176
lines changed

3 files changed

+174
-176
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,8 +1335,8 @@ InstructionCost RISCVTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
13351335
return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,
13361336
I);
13371337

1338+
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(ValTy);
13381339
if (Opcode == Instruction::Select && ValTy->isVectorTy()) {
1339-
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(ValTy);
13401340
if (CondTy->isVectorTy()) {
13411341
if (ValTy->getScalarSizeInBits() == 1) {
13421342
// vmandn.mm v8, v8, v9
@@ -1375,14 +1375,15 @@ InstructionCost RISCVTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
13751375
LT.second, CostKind);
13761376
}
13771377

1378-
if ((Opcode == Instruction::ICmp || Opcode == Instruction::FCmp) &&
1379-
ValTy->isVectorTy()) {
1380-
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(ValTy);
1381-
1382-
// Support natively.
1383-
if (CmpInst::isIntPredicate(VecPred))
1384-
return LT.first * 1;
1378+
if ((Opcode == Instruction::ICmp) && ValTy->isVectorTy() &&
1379+
CmpInst::isIntPredicate(VecPred)) {
1380+
// Use VMSLT_VV to represent VMSEQ, VMSNE, VMSLTU, VMSLEU, VMSLT, VMSLE
1381+
// provided they incur the same cost across all implementations
1382+
return LT.first *
1383+
getRISCVInstructionCost(RISCV::VMSLT_VV, LT.second, CostKind);
1384+
}
13851385

1386+
if ((Opcode == Instruction::FCmp) && ValTy->isVectorTy()) {
13861387
// If we do not support the input floating point vector type, use the base
13871388
// one which will calculate as:
13881389
// ScalarizeCost + Num * Cost for fixed vector,

0 commit comments

Comments
 (0)