Skip to content

[llvm][CodeGen] Update checking method of loop-carried phi in window scheduler #96288

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 3 commits into from
Jun 26, 2024

Conversation

huaatian
Copy link
Contributor

Added some logic to check loop-carried phis in the window scheduler. It
now includes the scenario where the preceding phi uses the virtual
register defined by the succeeding phi.

…scheduler

Added some logic to check loop-carried phis in the window scheduler. It
now includes the scenario where the preceding phi uses the virtual
register defined by the succeeding phi.
@huaatian
Copy link
Contributor Author

huaatian commented Jun 21, 2024

During our internal code review, we discovered that we had missed an equivalent loop-carried phi scenario. Previously, we checked the scenario where: "The virtual register defined by the preceding phi is used by the succeeding phi." There is an equivalent scenario where: "The preceding phi uses the virtual register defined by the succeeding phi." This patch improves the check to cover this scenario.
These scenarios were included in the Hexagon test cases, but since the window algorithm was not executed in that test case, no issues were encountered. We have now added the corresponding test cases.
image
image

@huaatian
Copy link
Contributor Author

Could you please review this patch? Thank you~ @arsenm

@arsenm arsenm added llvm:codegen mi-sched machine instruction scheduler labels Jun 21, 2024
Comment on lines 202 to 204
if (!MO.isReg())
continue;
if (MO.isDef()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You know the structure of phi so you can increment by 2 and check the single def separately

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

Comment on lines +195 to +196
SmallSet<Register, 8> PrevDefs;
SmallSet<Register, 8> PrevUses;
Copy link
Contributor

Choose a reason for hiding this comment

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

These sets aren't used outside of the lambda. Just make the lambda a helper function with these used locally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These sets are used to record the defs and uses of phis that have already been checked in the current MBB.
They need to be initialized and retain register information across multiple calls to the lambda.
Therefore, wouldn't it be better to place these sets outside the lambda?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

Comment on lines +195 to +196
SmallSet<Register, 8> PrevDefs;
SmallSet<Register, 8> PrevUses;
Copy link
Contributor

Choose a reason for hiding this comment

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

ok

// preceding phi is used by the succeeding phi;(2)The preceding phi uses the
// virtual register defined by the succeeding phi.
auto Def = Phi.getOperand(0);
if (Def.isReg()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Def must be a register. Don't try to handle invalid MIR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

}
for (unsigned I = 1, E = Phi.getNumOperands(); I != E; I += 2) {
auto Use = Phi.getOperand(I);
if (Use.isReg()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use must be a register

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@huaatian huaatian merged commit 811e505 into llvm:main Jun 26, 2024
7 checks passed
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
…scheduler (llvm#96288)

Added some logic to check loop-carried phis in the window scheduler. It now includes the scenario where the preceding phi uses the virtual register defined by the succeeding phi.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:codegen mi-sched machine instruction scheduler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants