[llvm] [TableGen] Add sub-register overflow tests for exact-fit and non-covered registers (PR #210529)
Taimuraz Kaitmazov via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 18 11:11:27 PDT 2026
https://github.com/atassis created https://github.com/llvm/llvm-project/pull/210529
Two more cases for the sub-register overflow check, both of which must not be
diagnosed, added to `subreg-index-overflow-allowed.td`:
- exact fit: a typed pair whose two halves tile the register exactly
(offset + size equals the register size), the boundary the check accepts
(it rejects only sub-registers that cover strictly more);
- not covered by sub-registers: a register without `CoveredBySubRegs` whose
explicit sub-register index runs past its size, which the check leaves alone.
Test only, no functional change. Both cases are new coverage: no in-tree target
exercises them today, and each was checked to fail if the corresponding guard in
`checkSubRegIndexSizes` regressed (the `>` boundary, and the `CoveredBySubRegs`
gate).
Follow-up to #206346.
**AI assistance:** drafted with AI help; the design and tests were authored and validated by me.
>From ec34f5911587147790d766784913603e21e27e72 Mon Sep 17 00:00:00 2001
From: Taimuraz Kaitmazov <atassikay38 at gmail.com>
Date: Sat, 18 Jul 2026 21:09:23 +0300
Subject: [PATCH] [TableGen] Add sub-register overflow tests for exact-fit and
non-covered registers
Two more cases for the sub-register overflow check, both of which must not be
diagnosed, added to subreg-index-overflow-allowed.td:
- exact fit: a typed pair whose two halves tile the register exactly
(offset + size equals the register size), the boundary the check accepts
(it rejects only sub-registers that cover strictly more);
- not covered by sub-registers: a register without CoveredBySubRegs whose
explicit sub-register index runs past its size, which the check leaves alone.
Test only, no functional change. Both cases are new coverage: no in-tree
target exercises them today, and each was checked to fail if the corresponding
guard in checkSubRegIndexSizes regressed (the > boundary, and the
CoveredBySubRegs gate).
---
.../TableGen/subreg-index-overflow-allowed.td | 31 +++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/llvm/test/TableGen/subreg-index-overflow-allowed.td b/llvm/test/TableGen/subreg-index-overflow-allowed.td
index 86afdd800692d..c1e18837ff948 100644
--- a/llvm/test/TableGen/subreg-index-overflow-allowed.td
+++ b/llvm/test/TableGen/subreg-index-overflow-allowed.td
@@ -29,9 +29,36 @@ def StridedRC : MyClass<64, [untyped], (add StridedPair)>;
def DensePair : RegisterTuples<[lo2, hi2], [(add R4, R6), (add R5, R7)]>;
def UntypedRC : MyClass<8, [untyped], (add DensePair)>;
+// (3) Exact fit: a typed 64-bit pair whose two 32-bit halves tile exactly
+// [0,64). offset+size equals the register size, which is the boundary case;
+// the check rejects sub-registers that cover strictly more, so this is fine.
+def elo : SubRegIndex<32, 0>;
+def ehi : SubRegIndex<32, 32>;
+def E0 : MyReg<"e0">;
+def E1 : MyReg<"e1">;
+def EGPR : MyClass<32, [i32], (add E0, E1)>;
+let SubRegIndices = [elo, ehi] in
+ def EP0 : MyReg<"ep0", [E0, E1]>;
+def ExactRC : MyClass<64, [i64], (add EP0)>;
+
+// (4) Not covered by sub-registers: a register that does not set
+// CoveredBySubRegs makes no full-tiling promise, so an explicit SubRegIndex
+// running past its size ([0,32)+[32,96) = 96 > 64) is that register's own
+// business and must not be diagnosed.
+def nlo : SubRegIndex<32, 0>;
+def nhi : SubRegIndex<64, 32>;
+def N0 : MyReg<"n0">;
+def N1 : MyReg<"n1">;
+def NGPR : MyClass<32, [i32], (add N0, N1)>;
+let SubRegIndices = [nlo, nhi] in
+ def NC0 : Register<"nc0"> { let Namespace = "Test"; let SubRegs = [N0, N1]; }
+def NotCoveredRC : MyClass<64, [i64], (add NC0)>;
+
def TestTarget : Target;
-// Both synthesized tuples must be emitted, i.e. neither was rejected by the
-// sub-register overflow check.
+// Every synthesized/explicit register below must be emitted, i.e. none was
+// rejected by the sub-register overflow check.
// CHECK-DAG: R0_R1 =
// CHECK-DAG: R4_R5 =
+// CHECK-DAG: EP0 =
+// CHECK-DAG: NC0 =
More information about the llvm-commits
mailing list