Skip to content

6.0: [PrunedLiveness] Fix boundary check for dead-ends. #73691

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

Explanation: Fix an edge-case in a fundamental SIL utility.

The PrunedLiveness utility is the fundamental tool used in the SIL optimizer to track where a value is live. For example, CSE uses it by way of the tool used to replace uses in OSSA, namely OwnershipRAUWHelper. PrunedLiveness allows clients to specify the points at which a value is known to be live. It uses those points to determine all places in the function where a value is live.

Often (and as used by OwnershipRAUWHelper) this is done by only considering the consuming uses. So long as a value must be consumed on all paths this makes sense: the consuming uses are the last uses of the value; everything before them is live, everything after them is dead. While soon (via LifetimeCompletion) it will be a correct and verified assumption that a value is consumed on all paths, unfortunately, currently, it is not: a value needn't be consumed on all paths. In particular, it can be "leaked" in so-called "dead-end blocks". A "dead-end block" is a block from which there are no function exiting paths--infinite loops, blocks that trap, and blocks all paths out of which lead into one or the other of those.

The lack of consumes in dead-end blocks means that it's not enough to only consider only consuming uses to determine whether a value is live. Special care must be taken with the dead-end blocks. Previously, it was only checked whether the block in question was a dead-end block; if so, the value was determined to be live within the block. That was not correct, however. If the value is consumed in a dead-end block, it is not available after that consume. Additionally, if the value is consumed on some but not all paths into the dead-end block, the value would not be available in it. Here, this check is tightened to only consider a dead-end block to be live if (1) the value is not consumed in the block and (2) the value is actually available in it (i.e. if the value is not consumed on any path into the block).

Fixes a SIL verifier error when building a simple project with an infinite loop for embedded.

Scope: Affects SIL optimizations.
Issue: rdar://126965232
Original PR: #73647
Risk: Low. Corrects and tightens an edge case.
Testing: Added a SIL test and the original source-level test.
Reviewer: Andrew Trick ( @atrick )

In preparation to make it more complex.
Consider dead, dead-end blocks within the availability boundary to be
within the boundary.

rdar://126965232
@nate-chandler nate-chandler requested a review from a team as a code owner May 17, 2024 01:28
@nate-chandler nate-chandler requested a review from tbkka May 17, 2024 01:28
Pick up the version committed on main.
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler enabled auto-merge May 17, 2024 03:31
@nate-chandler nate-chandler merged commit 625e3a5 into swiftlang:release/6.0 May 17, 2024
5 checks passed
@nate-chandler nate-chandler deleted the cherrypick/release/6.0/rdar128077404 branch May 17, 2024 10:39
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