Skip to content

[Mem2Reg] Skip load [take] of cast projections. #41751

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

Conversation

nate-chandler
Copy link
Contributor

Already, load [take]s of struct_element_addr|tuple_element_addr projections resulted in Mem2Reg bailing. Expand that to include load [take]s involving unchecked_addr_cast.

To handle load [take]s of (struct|tuple)_element_addr projections, it would be necessary to replace the running value with a value obtained from the original product by recursive destructuring, replacing the value at the load [take]n address with undef, and then restructuring.

To handle load [take]s of cast projections, it would be necessary to use unchecked_value_cast instead of unchecked_bitwise_cast. But we would need to still use unchecked_bitwise_cast in the case of load [copy] because otherwise we would lose the original value--unchecked_value_cast forwards ownership, and not all casts can be reversed (because they may narrow).

For now, just bail out in the face of these complex load [take]s.

Already, load [take]s of struct_element_addr|tuple_element_addr
projections resulted in Mem2Reg bailing.  Expand that to include load
[take]s involving unchecked_addr_cast.

To handle load [take]s of (struct|tuple)_element_addr projections, it
would be necessary to replace the running value with a value obtained
from the original product by recursive destructuring, replacing the
value at the load [take]n address with undef, and then restructuring.

To handle load [take]s of cast projections, it would be necessary to use
unchecked_value_cast instead of unchecked_bitwise_cast.  But we would
need to still use unchecked_bitwise_cast in the case of load [copy]
because otherwise we would lose the original value--unchecked_value_cast
forwards ownership, and not all casts can be reversed (because they may
narrow).

For now, just bail out in the face of these complex load [take]s.
@nate-chandler nate-chandler requested a review from atrick March 9, 2022 17:00
@nate-chandler
Copy link
Contributor Author

@swift-ci please 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.

Thanks for fixing Mem2Reg. Glad you caught this.

@nate-chandler nate-chandler merged commit 4343d94 into swiftlang:main Mar 10, 2022
@nate-chandler nate-chandler deleted the mem2reg/bail-on-load-take-complex-projections branch March 10, 2022 01:14
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