[llvm] [CodeGen] Allow negative frame indicies in Register class. (PR #164459)
Mikhail Gudim via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 23 07:13:57 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);
+ unsigned FIMasked = FI & Register::StackSlotMask;
+ assert(isUInt<MaxFrameIndexBitwidth>(FIMasked) &&
----------------
mgudim wrote:
Oh right, thanks!
https://github.com/llvm/llvm-project/pull/164459
More information about the llvm-commits
mailing list