Skip to content

[CodeGen] For ad hoc aliasing, additional regUnits are needed to fix lanemask representation #139206

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions llvm/utils/TableGen/Common/CodeGenRegisters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,20 +424,36 @@ CodeGenRegister::computeSubRegs(CodeGenRegBank &RegBank) {
// These units correspond to the maximal cliques in the register overlap
// graph which is optimal.
//
// When there is ad hoc aliasing, we simply create one unit per edge in the
// undirected ad hoc aliasing graph. Technically, we could do better by
// identifying maximal cliques in the ad hoc graph, but cliques larger than 2
// are extremely rare anyway (I've never seen one), so we don't bother with
// the added complexity.
// When there is ad hoc aliasing, while we create one unit per edge in the
// undirected ad hoc aliasing graph to represent aliasing, one unit per each
// node leaf register is needed extra to identify them uniquely, in case these
// aliasing register are used as subregister(with disjoint lanemasks) to have
// an accurate lanemask generation for these leaf register.
// For example, In VE, SX0 is made out of disjoint subregister SW0 & SF0
// respectively, where SF0 is an alias for SW0. So while 2 register units will
// uniquely define these 2 subregister, the shared register unit will account
// for aliasing.
//
// Technically, we could do better by identifying maximal cliques in the ad
// hoc graph, but cliques larger than 2 are extremely rare anyway (I've never
// seen one), so we don't bother with the added complexity.
//
// Create a RegUnit for leaf register that uniquely defines it, which has
// explicit alias registers.
if (RegUnits.empty() && !ExplicitAliases.empty())
RegUnits.set(RegBank.newRegUnit(this));
for (CodeGenRegister *AR : ExplicitAliases) {
// Only visit each edge once.
if (AR->SubRegsComplete)
continue;
// Create a RegUnit representing this alias edge, and add it to both
// registers.
unsigned Unit = RegBank.newRegUnit(this, AR);
RegUnits.set(Unit);
AR->RegUnits.set(Unit);
unsigned SharedUnit = RegBank.newRegUnit(this, AR);
RegUnits.set(SharedUnit);
AR->RegUnits.set(SharedUnit);

// Create a RegUnit that uniquely defines the alias leaf register nodes.
AR->RegUnits.set(RegBank.newRegUnit(AR));
}

// Finally, create units for leaf registers without ad hoc aliases. Note that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative implementation, could you simply move this block before the "Absent any ad hoc aliasing..." block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so? Because the handling of leaf register without ad hoc aliasing is really happening after this from line 456 if you see!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current logic is:

  1. Inherit regunits from subregs.
  2. Add a regunit for each alias.
  3. If we have no regunits after #⁠1 and #⁠2, it must be a leaf without aliases. Give it a new unique regunit.

I am suggesting swapping #⁠2 and #⁠3:

  1. Inherit regunits from subregs.
  2. If we have no regunits after #⁠1, it must be a leaf. Give it a new unique regunit.
  3. Add a regunit for each alias.

I think this gives the desired behavior.

Expand Down Expand Up @@ -2675,6 +2691,13 @@ void CodeGenRegBank::printRegUnitNames(ArrayRef<unsigned> Units) const {
dbgs() << ' ' << RegUnits[Unit].Roots[0]->getName();
else
dbgs() << " #" << Unit;

if (RegUnits[Unit].Roots[1]) {
if (Unit < NumNativeRegUnits)
dbgs() << '~' << RegUnits[Unit].Roots[1]->getName();
else
dbgs() << "~#" << Unit;
}
}
dbgs() << '\n';
}
Loading