[llvm] [GlobalISel] Use named constant for impossible repair cost (PR #180490)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 9 01:14:01 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-globalisel
Author: Eliz Habiboullah (elizhabiboullah)
<details>
<summary>Changes</summary>
replace magic value `std::numeric_limits<unsigned>::max()` with a named constant `ImpossibleRepairCost` to improve readability
---
Full diff: https://github.com/llvm/llvm-project/pull/180490.diff
1 Files Affected:
- (modified) llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp (+9-4)
``````````diff
diff --git a/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp b/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp
index 5db631be32acd..4dfd5179a4e56 100644
--- a/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp
@@ -51,6 +51,12 @@
using namespace llvm;
+/// Cost value representing an impossible or invalid repairing.
+/// This matches the value returned by RegisterBankInfo::copyCost() and
+/// RegisterBankInfo::getBreakDownCost() when the cost cannot be computed.
+static constexpr unsigned ImpossibleRepairCost =
+ std::numeric_limits<unsigned>::max();
+
static cl::opt<RegBankSelect::Mode> RegBankSelectMode(
cl::desc("Mode of the RegBankSelect pass"), cl::Hidden, cl::Optional,
cl::values(clEnumValN(RegBankSelect::Mode::Fast, "regbankselect-fast",
@@ -278,12 +284,11 @@ uint64_t RegBankSelect::getRepairCost(
// repairing placement.
unsigned Cost = RBI->copyCost(*DesiredRegBank, *CurRegBank,
RBI->getSizeInBits(MO.getReg(), *MRI, *TRI));
- // TODO: use a dedicated constant for ImpossibleCost.
- if (Cost != std::numeric_limits<unsigned>::max())
+ if (Cost != ImpossibleRepairCost)
return Cost;
// Return the legalization cost of that repairing.
}
- return std::numeric_limits<unsigned>::max();
+ return ImpossibleRepairCost;
}
const RegisterBankInfo::InstructionMapping &RegBankSelect::findBestMapping(
@@ -535,7 +540,7 @@ RegBankSelect::MappingCost RegBankSelect::computeMapping(
uint64_t RepairCost = getRepairCost(MO, ValMapping);
// This is an impossible to repair cost.
- if (RepairCost == std::numeric_limits<unsigned>::max())
+ if (RepairCost == ImpossibleRepairCost)
return MappingCost::ImpossibleCost();
// Bias used for splitting: 5%.
``````````
</details>
https://github.com/llvm/llvm-project/pull/180490
More information about the llvm-commits
mailing list