Skip to content

LoopRotate: don't rotate loops where the header block branches to a dead-end block. #78781

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 1 commit into from
Jan 22, 2025

Conversation

eeckstein
Copy link
Contributor

Incomplete liveranges in the dead-end exit block can cause a missing adjacent phi-argument for a re-borrow if there is a borrow-scope is in the loop. But even when we have complete lifetimes, it's probably not worth rotating a loop where the header block branches to a dead-end block.

Fixes a SIL verifier crash

…ead-end block.

Incomplete liveranges in the dead-end exit block can cause a missing adjacent phi-argument for a re-borrow if there is a borrow-scope is in the loop.
But even when we have complete lifetimes, it's probably not worth rotating a loop where the header block branches to a dead-end block.

Fixes a SIL verifier crash
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci apple silicon benchmark

Copy link
Contributor

@meg-gupta meg-gupta left a comment

Choose a reason for hiding this comment

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

lgtm

@atrick
Copy link
Contributor

atrick commented Jan 21, 2025

it's probably not worth rotating a loop where the header block branches to a dead-end block.

I thought that was actually the primary use case for loop rotation--making sure the trap condition dominates the loop.

@eeckstein
Copy link
Contributor Author

@swift-ci smoke test linux

@eeckstein
Copy link
Contributor Author

I thought that was actually the primary use case for loop rotation--making sure the trap condition dominates the loop.

That's a good point. But usually trap conditions are optimized to non-control flow cond_fail instructions. So loop rotation does not consider those anyway.
It just can happen some times that a cond_br - cond_fail true pair is not optimized yet when loop rotation runs.

I think we want another kind of optimization which moves cond_fail instructions out of the loop for the purpose of removing them in the loop.

@eeckstein eeckstein merged commit 90cbaec into swiftlang:main Jan 22, 2025
5 of 6 checks passed
@eeckstein eeckstein deleted the fix-loop-rotate branch January 22, 2025 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants