Skip to content

LoopRotate: Fix avoiding copy_value hoisted to the pre-header #62399

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
Dec 6, 2022

Conversation

meg-gupta
Copy link
Contributor

copy_value is marked as having no side effects.
Teach LoopRotate to avoid moving it to the pre header and instead duplicate it while rotating the loop.

copy_value is marked as having no side effects.
Teach LoopRotate to avoid moving it to the pre header and instead duplicate it while rotating the loop.
@meg-gupta
Copy link
Contributor Author

@swift-ci test

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

How does loop rotate handle other instructions which "may retain"?
Isn't copy_value considered to have a "retain" side effect? If not, that seems like a bigger bug.

@meg-gupta
Copy link
Contributor Author

LoopRotate looks for mayHaveSideEffects - https://github.com/apple/swift/blob/5b9aef91f8e96dcc82ac3828c18fa26473d17fe6/lib/SILOptimizer/LoopTransforms/LoopRotate.cpp#L116

copy_value is marked as having no side effects

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

Meghana pointed out that in copy_value is not actually supposed to have side effects. I think this change is fine and we can discuss how to move forward in parallel

@atrick
Copy link
Contributor

atrick commented Dec 6, 2022

@eeckstein Here's the issue:

In OSSA copy_value does not have any side-effects for the purpose of deleting the instruction or moving code around the instructions. As long as the OSSA constraints still hold-up, those transformations are legal. So, in that sense "may-retain" is false. But for the purpose of hoisting/sinking the copy_value itself, it does perform a retain. So in that sense, "may-retain" is true. Any idea how we want to model this kind of side-effect going forward?

@meg-gupta meg-gupta merged commit 9774e98 into swiftlang:main Dec 6, 2022
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.

2 participants