-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[NFC][X86] Reorder the registers to reduce unnecessary iterations #70222
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1d324d5
[X86] Reorder the register
KanRobert 2e34f1b
Update API
KanRobert 9ebb155
format code
KanRobert 3b279bc
Add asserts and comments
KanRobert 9d3bec6
Leave the logic in X86RegisterInfo::getNumSupportedRegs to next commit
KanRobert c3a6d36
Update non-x86 tests
KanRobert ee6b711
Revert "Update non-x86 tests"
KanRobert 9814552
Reorder for X86 only
KanRobert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -604,8 +604,9 @@ BitVector X86RegisterInfo::getReservedRegs(const MachineFunction &MF) const { | |
} | ||
} | ||
if (!Is64Bit || !MF.getSubtarget<X86Subtarget>().hasAVX512()) { | ||
for (unsigned n = 16; n != 32; ++n) { | ||
for (MCRegAliasIterator AI(X86::XMM0 + n, this, true); AI.isValid(); ++AI) | ||
for (unsigned n = 0; n != 16; ++n) { | ||
for (MCRegAliasIterator AI(X86::XMM16 + n, this, true); AI.isValid(); | ||
++AI) | ||
Reserved.set(*AI); | ||
} | ||
} | ||
|
@@ -616,6 +617,26 @@ BitVector X86RegisterInfo::getReservedRegs(const MachineFunction &MF) const { | |
return Reserved; | ||
} | ||
|
||
unsigned X86RegisterInfo::getNumSupportedRegs(const MachineFunction &MF) const { | ||
// All existing Intel CPUs that support AMX support AVX512 and all existing | ||
// Intel CPUs that support APX support AMX. AVX512 implies AVX. | ||
// | ||
// We enumerate the registers in X86GenRegisterInfo.inc in this order: | ||
// | ||
// Registers before AVX512, | ||
// AVX512 registers (X/YMM16-31, ZMM0-31, K registers) | ||
// AMX registers (TMM) | ||
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. We can also see the difference by the update in llvm/test/CodeGen/X86/ipra-reg-usage.ll |
||
// APX registers (R16-R31) | ||
// | ||
// and try to return the minimum number of registers supported by the target. | ||
|
||
assert((X86::R15WH + 1 == X86 ::YMM0) && (X86::YMM15 + 1 == X86::K0) && | ||
(X86::K6_K7 + 1 == X86::TMMCFG) && | ||
(X86::TMM7 + 1 == X86::NUM_TARGET_REGS) && | ||
"Register number may be incorrect"); | ||
return X86::NUM_TARGET_REGS; | ||
} | ||
|
||
bool X86RegisterInfo::isArgumentRegister(const MachineFunction &MF, | ||
MCRegister Reg) const { | ||
const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>(); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 want to take a step back.
Have you tried checking MRI->isReserved(Reg) here? Does that do anything to improve compile time?
Where is the time spent?
Am I reading this right, that it calls HandlePhysRegKill on the super register anytime it finds one of the subregisters is clobbered? Even if its already called it before?
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 did an analysis on the spent time there #67702 (comment).
The extra time is spent on iterations over the new registers and new register classes. LiveVariables is one of the passes with the greatest impact b/c it iterates them for each basic block. Besides, for LiveVariables and some other passes, the new registers make a bigger regmask and regset, and then operations on the regmask and regset take more time too, including allocation and loopup, etc.
MRI->isReserved(Reg)
? I think it's a AArch64 function only and even not used by X86 at all.My understanding is same as yours.
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.
MRI->isReserved(Reg) doesn't use the information from X86RegisterInfo::getReservedRegs?
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 misunderstood your idea...
After testing, I find checking
MRI->isReserved(Reg)
does not improve compile time, instead, it will bring 0.2% instruction count regression.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.
FYI LiveVariables is deprecated and we should work towards getting rid of it. LiveIntervals has been the replacement for ages
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.
What do you mean by "deprecated"? I see this function is still called when compiling workloads.
And according to the comment #67702 (comment) , we have not got rid of LiveVariables completely
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.
As in all uses of it should be removed and replaced with LiveIntervals. You still see it because nobody ever completed the work to remove it
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 see. But currently LiveVariables brings about 0.3% instruction count regression when I introduce new registers in #67702. If the regression is intolerable, then it will block my APX enabling work. I have to resolve it to before the migration is complete.
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.
How much work is left to remove LIveVariables?
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.
@jayfoad commented in #67702. I believe he/she knows more about that than me.