[llvm] a9eeb15 - [Tablegen] Fix condition to report when lanemask overflows (#181810)

via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 6 00:55:11 PST 2026


Author: Petr Vesely
Date: 2026-03-06T09:55:06+01:00
New Revision: a9eeb151fb5681fb254ad8da891424d2fbc033c0

URL: https://github.com/llvm/llvm-project/commit/a9eeb151fb5681fb254ad8da891424d2fbc033c0
DIFF: https://github.com/llvm/llvm-project/commit/a9eeb151fb5681fb254ad8da891424d2fbc033c0.diff

LOG: [Tablegen] Fix condition to report when lanemask overflows (#181810)

This PR:

Fixes a slight off-by-one error in the check for how many bits are
allocated for subreg lane masks. If 65 subreg lanes are used, it fails
later, but the error message is not clear as to what has occured.

Added: 
    llvm/test/TableGen/SubRegsLaneBitmask.td

Modified: 
    llvm/utils/TableGen/Common/CodeGenRegisters.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/TableGen/SubRegsLaneBitmask.td b/llvm/test/TableGen/SubRegsLaneBitmask.td
new file mode 100644
index 0000000000000..68c8aa5971c30
--- /dev/null
+++ b/llvm/test/TableGen/SubRegsLaneBitmask.td
@@ -0,0 +1,12 @@
+// RUN: not llvm-tblgen -gen-register-info -register-info-debug -I %p/../../include %s -o - 2>&1  | FileCheck %s
+include "llvm/Target/Target.td"
+def TestTarget : Target;
+
+foreach Index = 0...64 in {
+  def sub#Index : SubRegIndex<32, !shl(Index, 5)>;
+}
+
+def A : Register<"">;
+def TestRC : RegisterClass<"Test", [i32], 0, (add A)>;
+
+// CHECK: error: Ran out of lanemask bits to represent subregister sub64

diff  --git a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
index 0a0495ee4d458..98aa63b3adb2d 100644
--- a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
@@ -1523,7 +1523,7 @@ void CodeGenRegBank::computeSubRegLaneMasks() {
   CoveringLanes = LaneBitmask::getAll();
   for (CodeGenSubRegIndex &Idx : SubRegIndices) {
     if (Idx.getComposites().empty()) {
-      if (Bit > LaneBitmask::BitWidth) {
+      if (Bit >= LaneBitmask::BitWidth) {
         PrintFatalError(
             Twine("Ran out of lanemask bits to represent subregister ") +
             Idx.getName());


        


More information about the llvm-commits mailing list