Skip to content

Commit fb60d03

Browse files
committed
[VPlan] Return non-option cost from getCostForRecipeWithOpcode (NFC).
getCostForRecipeWithOpcode must only be called with supported opcodes. Directly return the cost, and add llvm_unreachable to catch unhandled cases.
1 parent 30f4781 commit fb60d03

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,9 +918,8 @@ struct VPRecipeWithIRFlags : public VPSingleDefRecipe, public VPIRFlags {
918918
void execute(VPTransformState &State) override = 0;
919919

920920
/// Compute the cost for this recipe for \p VF, using \p Opcode and \p Ctx.
921-
std::optional<InstructionCost>
922-
getCostForRecipeWithOpcode(unsigned Opcode, ElementCount VF,
923-
VPCostContext &Ctx) const;
921+
InstructionCost getCostForRecipeWithOpcode(unsigned Opcode, ElementCount VF,
922+
VPCostContext &Ctx) const;
924923
};
925924

926925
/// Helper to access the operand that contains the unroll part for this recipe

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ Value *VPInstruction::generate(VPTransformState &State) {
978978
}
979979
}
980980

981-
std::optional<InstructionCost> VPRecipeWithIRFlags::getCostForRecipeWithOpcode(
981+
InstructionCost VPRecipeWithIRFlags::getCostForRecipeWithOpcode(
982982
unsigned Opcode, ElementCount VF, VPCostContext &Ctx) const {
983983
Type *ScalarTy = Ctx.Types.inferScalarType(this);
984984
Type *ResultTy = VF.isVector() ? toVectorTy(ScalarTy, VF) : ScalarTy;
@@ -1044,7 +1044,7 @@ std::optional<InstructionCost> VPRecipeWithIRFlags::getCostForRecipeWithOpcode(
10441044
{TTI::OK_AnyValue, TTI::OP_None}, CtxI);
10451045
}
10461046
}
1047-
return std::nullopt;
1047+
llvm_unreachable("called for unsupported opcode");
10481048
}
10491049

10501050
InstructionCost VPInstruction::computeCost(ElementCount VF,
@@ -1059,7 +1059,7 @@ InstructionCost VPInstruction::computeCost(ElementCount VF,
10591059
assert(!doesGeneratePerAllLanes() &&
10601060
"Should only generate a vector value or single scalar, not scalars "
10611061
"for all lanes.");
1062-
return *getCostForRecipeWithOpcode(
1062+
return getCostForRecipeWithOpcode(
10631063
getOpcode(),
10641064
vputils::onlyFirstLaneUsed(this) ? ElementCount::getFixed(1) : VF, Ctx);
10651065
}
@@ -2206,7 +2206,7 @@ InstructionCost VPWidenRecipe::computeCost(ElementCount VF,
22062206
case Instruction::ExtractValue:
22072207
case Instruction::ICmp:
22082208
case Instruction::FCmp:
2209-
return *getCostForRecipeWithOpcode(getOpcode(), VF, Ctx);
2209+
return getCostForRecipeWithOpcode(getOpcode(), VF, Ctx);
22102210
default:
22112211
llvm_unreachable("Unsupported opcode for instruction");
22122212
}
@@ -3151,15 +3151,15 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
31513151
case Instruction::Xor:
31523152
case Instruction::ICmp:
31533153
case Instruction::FCmp:
3154-
return *getCostForRecipeWithOpcode(getOpcode(), ElementCount::getFixed(1),
3155-
Ctx) *
3154+
return getCostForRecipeWithOpcode(getOpcode(), ElementCount::getFixed(1),
3155+
Ctx) *
31563156
(isSingleScalar() ? 1 : VF.getFixedValue());
31573157
case Instruction::SDiv:
31583158
case Instruction::UDiv:
31593159
case Instruction::SRem:
31603160
case Instruction::URem: {
3161-
InstructionCost ScalarCost = *getCostForRecipeWithOpcode(
3162-
getOpcode(), ElementCount::getFixed(1), Ctx);
3161+
InstructionCost ScalarCost =
3162+
getCostForRecipeWithOpcode(getOpcode(), ElementCount::getFixed(1), Ctx);
31633163
if (isSingleScalar())
31643164
return ScalarCost;
31653165

0 commit comments

Comments
 (0)