Skip to content

Commit

Permalink
[RISCV][TTI] Scale the cost of ICmp with LMUL (#88235)
Browse files Browse the repository at this point in the history
Use the Val type to estimate the instruction cost for ICmp.
  • Loading branch information
arcbbb committed Apr 16, 2024
1 parent 2e26ee9 commit f3a8112
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 176 deletions.
17 changes: 9 additions & 8 deletions llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1335,8 +1335,8 @@ InstructionCost RISCVTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,
I);

std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(ValTy);
if (Opcode == Instruction::Select && ValTy->isVectorTy()) {
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(ValTy);
if (CondTy->isVectorTy()) {
if (ValTy->getScalarSizeInBits() == 1) {
// vmandn.mm v8, v8, v9
Expand Down Expand Up @@ -1375,14 +1375,15 @@ InstructionCost RISCVTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
LT.second, CostKind);
}

if ((Opcode == Instruction::ICmp || Opcode == Instruction::FCmp) &&
ValTy->isVectorTy()) {
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(ValTy);

// Support natively.
if (CmpInst::isIntPredicate(VecPred))
return LT.first * 1;
if ((Opcode == Instruction::ICmp) && ValTy->isVectorTy() &&
CmpInst::isIntPredicate(VecPred)) {
// Use VMSLT_VV to represent VMSEQ, VMSNE, VMSLTU, VMSLEU, VMSLT, VMSLE
// provided they incur the same cost across all implementations
return LT.first *
getRISCVInstructionCost(RISCV::VMSLT_VV, LT.second, CostKind);
}

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

0 comments on commit f3a8112

Please sign in to comment.