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

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 27 14:09:58 PDT 2025


================
@@ -0,0 +1,35 @@
+//===- RegisterTest.cpp -----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGen/Register.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+TEST(RegisterTest, Idx2StackSlot) {
+  EXPECT_EQ(Register::index2StackSlot(0), Register::StackSlotZero);
+  EXPECT_EQ(Register::index2StackSlot(1), Register::StackSlotZero | 1);
+  EXPECT_EQ(Register::index2StackSlot(-1),
+            Register::StackSlotZero | Register::StackSlotMask);
+  // check that we do not crash on the highest possible value of frame index.
+  EXPECT_NO_FATAL_FAILURE(Register::index2StackSlot((1 << 29) - 1));
----------------
topperc wrote:

Use named constants for 29 here and the line below?

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


More information about the llvm-commits mailing list