-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[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
[CodeGen] For ad hoc aliasing, additional regUnits are needed to fix lanemask representation #139206
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -424,20 +424,33 @@ 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. | ||
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 now corresponds uniquely to each of the both | ||
// alias leaf register nodes. | ||
RegUnits.set(RegBank.newRegUnit(this)); | ||
AR->RegUnits.set(RegBank.newRegUnit(AR)); | ||
} | ||
|
||
// Finally, create units for leaf registers without ad hoc aliases. Note that | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current logic is:
I am suggesting swapping #2 and #3:
I think this gives the desired behavior. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This won't do as suppose intially once There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, but it is pretty easy to fix that problem. See #139526 |
||
|
@@ -2675,6 +2688,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'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is assuming that a register that has aliases is also a leaf, i.e. it has no sburegs. I am not sure whether that is a valid assumption.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not have subregs at this point, as the register units are created corresponding only to leaf registers, while other regs (including aliases) inherit the regunits of their corresponding subregs. If you see few lines above this changes you would observe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am asking whether any target defines a register with both Aliases and SubRegs. Currently I don't think any in-tree target does that, but it seems like it should be possible (and maybe out-of-tree targets do it?). For example, if the VE register SW0 had subregs for its upper and lower 16 bit halves.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that might need some investigation Or I can add the test for that as suggested by you, that will make things clear. Yeah as you said the current implementation does not apparently seems to handle it, Better to look at it seaparately, can be tracked via added test?