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

David Green via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 15 03:41:21 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);
----------------
davemgreen wrote:

I have removed getValueOr and performed the check inline.

(It is a good thing to check for invalid costs even if they are unlikely to come up, to make things more robust. They shouldn't come up in already-present llvm-ir though ideally, most IR get some valid cost and the invalid costs are used for things that cannot be selected/legalized).

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


More information about the llvm-commits mailing list