[llvm] [CodeGen] Allow negative frame indicies in Register class. (PR #164459)

Mikhail Gudim via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 22 11:48:55 PDT 2025


================
@@ -87,7 +92,8 @@ class Register {
   /// Compute the frame index from a register value representing a stack slot.
   int stackSlotIndex() const {
     assert(isStack() && "Not a stack slot");
-    return static_cast<int>(Reg - Register::FirstStackSlot);
+    return static_cast<int>(
+        SignExtend64<MaxFrameIndexBitwidth>(Reg & Register::StackSlotMask));
----------------
mgudim wrote:

I thought `int` could be smaller then `int32_t` in theory. 

Actually, to me it looks like `stackSlotIndex` should return `int32_t`. If `int` is not 32 bits, the result may not be able to fit, no? 

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


More information about the llvm-commits mailing list