Skip to content

runtime: return the argument from swift_retain family of functions #11986

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 2 commits into from
Sep 19, 2017

Conversation

aschwaighofer
Copy link
Contributor

On architectures where the calling convention uses the same argument register as
return register this allows the argument register to be live through the calls. It also enables tail calls to be optimized in functions that call swift_retain as the last thing and return its argument.

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - cd45f34e29bbc5fcfcba5392134b59d068d33339

@gottesmm
Copy link
Contributor

gottesmm commented Sep 18, 2017

Can you add a little note in the commit message for 11b65c5 stating something along the lines of:

We used to perform this optimization via an optimization pass. This was ripped out some time ago in commit XXXX. Now by putting this attribute on swift_retain *, we get the same optimization for free via the backend register allocator.

@aschwaighofer aschwaighofer force-pushed the return_dest_from_retain branch 2 times, most recently from 693957d to 372fd79 Compare September 18, 2017 21:55
@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - cd45f34e29bbc5fcfcba5392134b59d068d33339

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - cd45f34e29bbc5fcfcba5392134b59d068d33339

On architectures where the calling convention uses the same argument register as
return register this allows the argument register to be live through the calls.

We use LLVM's 'returned' attribute on the parameter to facilitate this.

We used to perform this optimization via an optimization pass. This was ripped
out some time ago around commit 955e4ed.
By using LLVM's 'returned' attribute on swift_*retain, we get the same
optimization from the LLVM backend.
This improves x86-64 code generation to not having any stack operations on the fast path.
@aschwaighofer aschwaighofer force-pushed the return_dest_from_retain branch from 372fd79 to bc68d51 Compare September 19, 2017 14:19
@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 372fd7923a2dd03781a9f267300d28fddd9a4246

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 372fd7923a2dd03781a9f267300d28fddd9a4246

@aschwaighofer aschwaighofer merged commit c112918 into swiftlang:master Sep 19, 2017
@rjmccall
Copy link
Contributor

Yay!

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.

4 participants