[llvm] [TableGen] Apply the implied subregidx optimization more widely (PR #149709)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 20 07:06:37 PDT 2025
https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/149709
inferMatchingSuperRegClass has an optimization to skip subreg indices
that are implied by ones it has already handled. Apply this optimization
for every subreg index that is fully supported by RC.
This gives more than 2x speed-up in inferMatchingSuperRegClass when
generating AMDGPUGenRegisterInfo.inc without changing the contents of
any generated files.
>From 187c00c033a40c73ce113bf2711aff6505004b05 Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Sun, 20 Jul 2025 15:02:24 +0100
Subject: [PATCH] [TableGen] Apply the implied subregidx optimization more
widely
inferMatchingSuperRegClass has an optimization to skip subreg indices
that are implied by ones it has already handled. Apply this optimization
for every subreg index that is fully supported by RC.
This gives more than 2x speed-up in inferMatchingSuperRegClass when
generating AMDGPUGenRegisterInfo.inc without changing the contents of
any generated files.
---
.../TableGen/Common/CodeGenRegisters.cpp | 34 +++++++++----------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
index f78427940b276..cd5515e757f8f 100644
--- a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
@@ -2352,6 +2352,23 @@ void CodeGenRegBank::inferMatchingSuperRegClass(
if (ImpliedSubRegIndices.contains(SubIdx))
continue;
+ // We can skip checking subregister indices that can be composed from
+ // the current SubIdx.
+ //
+ // Proof sketch: Let SubRC' be another register class and SubSubIdx
+ // a subregister index that can be composed from SubIdx.
+ //
+ // Calling this function with SubRC in place of RC ensures the existence
+ // of a subclass X of SubRC with the registers that have subregisters in
+ // SubRC'.
+ //
+ // The set of registers in RC with SubSubIdx in SubRC' is equal to the
+ // set of registers in RC with SubIdx in X (because every register in
+ // RC has a corresponding subregister in SubRC), and so checking the
+ // pair (SubSubIdx, SubRC') is redundant with checking (SubIdx, X).
+ for (const auto &SubSubIdx : SubIdx->getComposites())
+ ImpliedSubRegIndices.insert(SubSubIdx.second);
+
// Build list of (Sub, Super) pairs for this SubIdx, sorted by Sub. Note
// that the list may contain entries with the same Sub but different Supers.
SubRegs.clear();
@@ -2390,23 +2407,6 @@ void CodeGenRegBank::inferMatchingSuperRegClass(
if (SubSetVec.size() == RC->getMembers().size()) {
SubRC.addSuperRegClass(SubIdx, RC);
- // We can skip checking subregister indices that can be composed from
- // the current SubIdx.
- //
- // Proof sketch: Let SubRC' be another register class and SubSubIdx
- // a subregister index that can be composed from SubIdx.
- //
- // Calling this function with SubRC in place of RC ensures the existence
- // of a subclass X of SubRC with the registers that have subregisters in
- // SubRC'.
- //
- // The set of registers in RC with SubSubIdx in SubRC' is equal to the
- // set of registers in RC with SubIdx in X (because every register in
- // RC has a corresponding subregister in SubRC), and so checking the
- // pair (SubSubIdx, SubRC') is redundant with checking (SubIdx, X).
- for (const auto &SubSubIdx : SubIdx->getComposites())
- ImpliedSubRegIndices.insert(SubSubIdx.second);
-
continue;
}
More information about the llvm-commits
mailing list