Skip to content

6.2: [DestroyAddrHoisting] Don't fold into read access. #82573

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

@nate-chandler nate-chandler commented Jun 27, 2025

Explanation: Bail out of an optimization in DestroyAddrHoisting when it's invalid.

The pass folds destroy_addr instructions into copy_addr and load [copy] instructions to form copy_addr [take] and load [take] instructions respectively. It does this even when the source of the copy_addr or load [copy] is, rather than directly the address that is destroy_addr'd, an access scope for that address (begin_access %addr).

Previously, it would perform such folding even when the access scope was a [read]. This is invalid because such a transformation makes the access scope no longer be a [read]. This is a problem because analyses expect begin_access instructions to provide correct summaries. Furthermore, this is invalid in general because such an access scope may overlap with other read accesses to the same storage, and it is not allowed for a read access to overlap with a modify access.

Here, when folding into a copy_addr or load [copy] whose source is an access scope rather than directly the address being destroy_addr'd, it is checked that the access scope is not a [read].
Scope: Affects optimized code.
Issue: rdar://154407327
Original PR: #82557
Risk: Low, this makes the optimization more conservative.
Testing: Added tests.
Reviewer: Erik Eckstein ( @eeckstein ), Andrew Trick ( @atrick )

Narrowly fix a long-standing bug where destroy_addrs would be hoisted
into read access scopes, leaving the scope as a read despite the fact
that it modifies memory.  This is a problem for utilities which expect
access scopes to provide correct summaries.  Do this by refusing to fold
into access scopes which are marked `[read]`.

In a follow-up, we can reenable this folding, promoting each access
scope to a modify.  Doing so requires checking that there are no access
scopes which overlap with any of the access scopes which would be
promoted to modify.

rdar://154407327
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler marked this pull request as ready for review June 27, 2025 22:36
@nate-chandler nate-chandler requested a review from a team as a code owner June 27, 2025 22:36
@nate-chandler nate-chandler enabled auto-merge June 27, 2025 22:36
@nate-chandler nate-chandler merged commit 9b8e749 into swiftlang:release/6.2 Jun 28, 2025
5 checks passed
@nate-chandler nate-chandler deleted the cherrypick/release/6.2/rdar154407327 branch June 30, 2025 18:44
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