From 98b6f8dc699d789d834e5b6d810ed217f560aad0 Mon Sep 17 00:00:00 2001 From: David Green Date: Wed, 23 Apr 2025 07:46:27 +0100 Subject: [CostModel] Remove optional from InstructionCost::getValue() (#135596) InstructionCost is already an optional value, containing an Invalid state that can be checked with isValid(). There is little point in returning another optional from getValue(). Most uses do not make use of it being a std::optional, dereferencing the value directly (either isValid has been checked previously or the Cost is assumed to be valid). The one case that does in AMDGPU used value_or which has been replaced by a isValid() check. --- llvm/lib/CodeGen/SelectOptimize.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'llvm/lib/CodeGen/SelectOptimize.cpp') diff --git a/llvm/lib/CodeGen/SelectOptimize.cpp b/llvm/lib/CodeGen/SelectOptimize.cpp index 00148b0..13ed8f2 100644 --- a/llvm/lib/CodeGen/SelectOptimize.cpp +++ b/llvm/lib/CodeGen/SelectOptimize.cpp @@ -206,7 +206,7 @@ public: getI()->getOpcode(), I->getType(), TargetTransformInfo::TCK_Latency, {TargetTransformInfo::OK_AnyValue, TargetTransformInfo::OP_None}, {TTI::OK_UniformConstantValue, TTI::OP_PowerOf2}); - auto TotalCost = Scaled64::get(*Cost.getValue()); + auto TotalCost = Scaled64::get(Cost.getValue()); if (auto *OpI = dyn_cast(I->getOperand(1 - CondIdx))) { auto It = InstCostMap.find(OpI); if (It != InstCostMap.end()) @@ -1380,8 +1380,8 @@ std::optional SelectOptimizeImpl::computeInstCost(const Instruction *I) { InstructionCost ICost = TTI->getInstructionCost(I, TargetTransformInfo::TCK_Latency); - if (auto OC = ICost.getValue()) - return std::optional(*OC); + if (ICost.isValid()) + return std::optional(ICost.getValue()); return std::nullopt; } -- cgit v1.1