Skip to content

[ShrinkBorrowScope] Leave under rewritten copies. #61655

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 Oct 21, 2022

When shrinking a borrow scope like

%borrow = begin_borrow %value
barrier
%copy = copy_value %borrow
end_borrow %borrow

the copy will be rewritten to be a copy of the borrowee:

%borrow = begin_borrow %value
barrier
%copy = copy_value %value
                   ^^^^^^
end_borrow %borrow

If, as here, shrinking next encounters a barrier, then the insertion point will be that rewritten copy_value instruction.

In such a case, rather than creating a new end_borrow there and deleting the old, just reuse the old one. The lifetime of the value being copied will be canonicalized by CopyPropagation regardless.

When shrinking a borrow scope like

    %borrow = begin_borrow %value
    barrier
    %copy = copy_value %borrow
    end_borrow %borrow

the copy will be rewritten to be a copy of the borrowee:

    %borrow = begin_borrow %value
    barrier
    %copy = copy_value %value
                       ^^^^^^
    end_borrow %borrow

If, as here, shrinking next encounters a barrier, then the insertion
point will be that rewritten copy_value instruction.

In such a case, when rather than creating a new end_borrow there and
deleting the old, just reuse the old one.  The lifetime of the value
being copied will be canonicalized by CopyPropagation regardless.
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please benchmark

@nate-chandler
Copy link
Contributor Author

@swift-ci please test source compatibility

@nate-chandler nate-chandler merged commit a020791 into swiftlang:main Oct 21, 2022
@nate-chandler nate-chandler deleted the shrink_borrow_scope/dont_hoist_over_only_rewritten_copies branch October 21, 2022 23:34
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.

1 participant