[llvm] [CostModel] Remove optional from InstructionCost::getValue() (PR #135596)

Pierre van Houtryve via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 15 00:51:24 PDT 2025


================
@@ -205,8 +205,7 @@ static CostType calculateFunctionCosts(GetTTIFn GetTTI, Module &M,
             TTI.getInstructionCost(&I, TargetTransformInfo::TCK_CodeSize);
         assert(Cost != InstructionCost::getMax());
         // Assume expensive if we can't tell the cost of an instruction.
-        CostType CostVal =
-            Cost.getValue().value_or(TargetTransformInfo::TCC_Expensive);
+        CostType CostVal = Cost.getValueOr(TargetTransformInfo::TCC_Expensive);
----------------
Pierre-vh wrote:

> Maybe just add a check here and remove getValueOr()?

I wrote this assuming that Cost may not be possible to calculate for every instruction (maybe target intrinsics?).
If the cost is always calculated and cannot really fail then sure, we can replace this with an assert

https://github.com/llvm/llvm-project/pull/135596


More information about the llvm-commits mailing list