[llvm] [CodeGen] Allow negative frame indicies in Register class. (PR #164459)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 23 10:28:26 PDT 2025
================
@@ -35,19 +36,23 @@ class Register {
// DenseMapInfo<unsigned> uses -1u and -2u.
static_assert(std::numeric_limits<decltype(Reg)>::max() >= 0xFFFFFFFF,
"Reg isn't large enough to hold full range.");
- static constexpr unsigned FirstStackSlot = 1u << 30;
- static_assert(FirstStackSlot >= MCRegister::LastPhysicalReg);
+ static constexpr unsigned MaxFrameIndexBitwidth = 30;
+ static constexpr unsigned StackSlotZero = 1u << MaxFrameIndexBitwidth;
+ static constexpr const unsigned StackSlotMask = StackSlotZero - 1;
+ static_assert(StackSlotZero >= MCRegister::LastPhysicalReg);
static constexpr unsigned VirtualRegFlag = 1u << 31;
/// Return true if this is a stack slot.
constexpr bool isStack() const {
- return Register::FirstStackSlot <= Reg && Reg < Register::VirtualRegFlag;
+ return Register::StackSlotZero <= Reg && Reg < Register::VirtualRegFlag;
}
/// Convert a non-negative frame index to a stack slot register value.
static Register index2StackSlot(int FI) {
- assert(FI >= 0 && "Cannot hold a negative frame index.");
- return Register(FI + Register::FirstStackSlot);
+ assert(isInt<MaxFrameIndexBitwidth>(FI) &&
+ "Frame index must be at most 30 bit as an unsigned integer");
----------------
topperc wrote:
bit -> bits. And "unsigned" does not match the `isInt` check.
https://github.com/llvm/llvm-project/pull/164459
More information about the llvm-commits
mailing list