-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[TableGen] Apply the implied subregidx optimization more widely #149709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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.
@llvm/pr-subscribers-tablegen Author: Jay Foad (jayfoad) ChangesinferMatchingSuperRegClass has an optimization to skip subreg indices This gives more than 2x speed-up in inferMatchingSuperRegClass when Full diff: https://github.com/llvm/llvm-project/pull/149709.diff 1 Files Affected:
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;
}
|
Hi @jayfoad , I quickly tried this on a downstream back-end and see some differences in our A quick diff of the generated reg info shows a few differences along these lines for
Notably, all the differences are related to the union classes (RC1 union RC2) we use for Greedy's inflation mechanism. What seems to be happening is that
no longer adds, e.g., This is just a heads-up that there is at least one back-end where there are reg info differences, but I cannot yet say whether this is actually a problem (including in our own very complicated register hierarchy with a proliferation of long tuple classes, overlaps, and inflation classes). |
Thanks! It certainly makes sense that the diffs would be related to missing |
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.