Skip to content

[MachinePipeliner] Use VirtRegOrUnit instead of Register appropriately#177535

Open
kasuga-fj wants to merge 2 commits intollvm:mainfrom
kasuga-fj:pipeliner-use-virtregormcunit
Open

[MachinePipeliner] Use VirtRegOrUnit instead of Register appropriately#177535
kasuga-fj wants to merge 2 commits intollvm:mainfrom
kasuga-fj:pipeliner-use-virtregormcunit

Conversation

@kasuga-fj
Copy link
Contributor

Resolve the FIXMEs in MachinePipeliner added in #167730, primarily by replacing Register with VirtRegOrUnit where necessary to remove invalid static_casts. Based on my local testing, there was no noticeable performance impact.

Copy link
Contributor

@s-barannikov s-barannikov left a comment

Choose a reason for hiding this comment

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

I left a couple of comments, but I don't really know the algorithm and thus not confident of the changes.
In general, any functional change needs a regression test.

Comment on lines 1658 to 1659
for (MCRegUnit Unit : TRI->regunits(Reg.asMCReg()))
UpdateTargetRegs(VirtRegOrUnit(Unit));
Copy link
Contributor

Choose a reason for hiding this comment

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

This branch is unreachable: PHI register can never be a physical 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.

Removed the branch. I'm not familiar with these infrastructures so this may be a silly question, but is PHI register always a virtual register?

Copy link
Contributor

@s-barannikov s-barannikov Jan 23, 2026

Choose a reason for hiding this comment

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

but is PHI register always a virtual register

Yes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, thanks.

// Return true if Reg is reserved one, for example, stack pointer
bool isReservedRegister(Register Reg) const {
return Reg.isPhysical() && MRI.isReserved(Reg.asMCReg());
bool isReservedRegister(VirtRegOrUnit Reg) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment and the name don't match the implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor Author

@kasuga-fj kasuga-fj left a comment

Choose a reason for hiding this comment

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

Thanks for the comments.

In general, any functional change needs a regression test.

Yeah, but for various reasons, it's difficult to write meaningful tests for this part (not just here, but throughout the entire MachinePipeliner as well). This is definitely technical debt, but there isn't much I can do at this point.

Comment on lines 1658 to 1659
for (MCRegUnit Unit : TRI->regunits(Reg.asMCReg()))
UpdateTargetRegs(VirtRegOrUnit(Unit));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the branch. I'm not familiar with these infrastructures so this may be a silly question, but is PHI register always a virtual register?

// Return true if Reg is reserved one, for example, stack pointer
bool isReservedRegister(Register Reg) const {
return Reg.isPhysical() && MRI.isReserved(Reg.asMCReg());
bool isReservedRegister(VirtRegOrUnit Reg) const {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants