Skip to content

Commit 151128d

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. (cherry picked from commit fb60d03)
1 parent 994593f commit 151128d

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

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

903903
/// Compute the cost for this recipe for \p VF, using \p Opcode and \p Ctx.
904-
std::optional<InstructionCost>
905-
getCostForRecipeWithOpcode(unsigned Opcode, ElementCount VF,
906-
VPCostContext &Ctx) const;
904+
InstructionCost getCostForRecipeWithOpcode(unsigned Opcode, ElementCount VF,
905+
VPCostContext &Ctx) const;
907906
};
908907

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

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ Value *VPInstruction::generate(VPTransformState &State) {
901901
}
902902
}
903903

904-
std::optional<InstructionCost> VPRecipeWithIRFlags::getCostForRecipeWithOpcode(
904+
InstructionCost VPRecipeWithIRFlags::getCostForRecipeWithOpcode(
905905
unsigned Opcode, ElementCount VF, VPCostContext &Ctx) const {
906906
Type *ScalarTy = Ctx.Types.inferScalarType(this);
907907
Type *ResultTy = VF.isVector() ? toVectorTy(ScalarTy, VF) : ScalarTy;
@@ -967,7 +967,7 @@ std::optional<InstructionCost> VPRecipeWithIRFlags::getCostForRecipeWithOpcode(
967967
{TTI::OK_AnyValue, TTI::OP_None}, CtxI);
968968
}
969969
}
970-
return std::nullopt;
970+
llvm_unreachable("called for unsupported opcode");
971971
}
972972

973973
InstructionCost VPInstruction::computeCost(ElementCount VF,
@@ -982,7 +982,7 @@ InstructionCost VPInstruction::computeCost(ElementCount VF,
982982
assert(!doesGeneratePerAllLanes() &&
983983
"Should only generate a vector value or single scalar, not scalars "
984984
"for all lanes.");
985-
return *getCostForRecipeWithOpcode(
985+
return getCostForRecipeWithOpcode(
986986
getOpcode(),
987987
vputils::onlyFirstLaneUsed(this) ? ElementCount::getFixed(1) : VF, Ctx);
988988
}
@@ -2064,7 +2064,7 @@ InstructionCost VPWidenRecipe::computeCost(ElementCount VF,
20642064
case Instruction::ExtractValue:
20652065
case Instruction::ICmp:
20662066
case Instruction::FCmp:
2067-
return *getCostForRecipeWithOpcode(getOpcode(), VF, Ctx);
2067+
return getCostForRecipeWithOpcode(getOpcode(), VF, Ctx);
20682068
default:
20692069
llvm_unreachable("Unsupported opcode for instruction");
20702070
}
@@ -3040,16 +3040,16 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
30403040
case Instruction::AShr:
30413041
case Instruction::And:
30423042
case Instruction::Or:
3043-
case Instruction::Xor: {
3044-
return *getCostForRecipeWithOpcode(getOpcode(), ElementCount::getFixed(1),
3045-
Ctx) *
3043+
case Instruction::Xor:
3044+
return getCostForRecipeWithOpcode(getOpcode(), ElementCount::getFixed(1),
3045+
Ctx) *
30463046
(isSingleScalar() ? 1 : VF.getFixedValue());
30473047
case Instruction::SDiv:
30483048
case Instruction::UDiv:
30493049
case Instruction::SRem:
30503050
case Instruction::URem: {
3051-
InstructionCost ScalarCost = *getCostForRecipeWithOpcode(
3052-
getOpcode(), ElementCount::getFixed(1), Ctx);
3051+
InstructionCost ScalarCost =
3052+
getCostForRecipeWithOpcode(getOpcode(), ElementCount::getFixed(1), Ctx);
30533053
if (isSingleScalar())
30543054
return ScalarCost;
30553055

@@ -3076,7 +3076,6 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
30763076
break;
30773077
}
30783078
}
3079-
}
30803079

30813080
return Ctx.getLegacyCost(UI, VF);
30823081
}

0 commit comments

Comments
 (0)