[llvm] [TableGen] Apply the implied subregidx optimization more widely (PR #149709)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 20 07:07:11 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tablegen
Author: Jay Foad (jayfoad)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/149709.diff
1 Files Affected:
- (modified) llvm/utils/TableGen/Common/CodeGenRegisters.cpp (+17-17)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/149709
More information about the llvm-commits
mailing list