Skip to content

SILOptimizer: Add a new TempRValue optimization pass [4.0] #11364

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 1 commit into from
Aug 7, 2017

Conversation

eeckstein
Copy link
Contributor

Description: This is a separate optimization that detects short-lived temporaries that can be eliminated. This is necessary now that SILGen no longer performs basic RValue forwarding in some cases.

Scope of the issue: Originally we thought it's just a 30% performance regression for a certain type of micro benchmarks. But the problem is worse. It can happen that in a mutating struct method the whole struct is copied, even if the copy is not done in the source code. So this performance regression can be significant.

Origination: The performance regression was introduced with a SILGen bug fix: #11026

Tested: By lnt tests

Risk: Low. Although the patch adds quite a few lines of codes, I think the risk is low, because:
-) The logic of the new optimization pass is easy to understand, so there should be no conceptual problems.
-) 3 people reviewed the change
-) It's an isolated optimization pass which just runs once at the beginning of the optimization pipeline. So it should not see any unusual code generated by other optimizations. Also, it does not interfere with the internal state of another optimization (like CopyForwarding, which was the case in the first implementation).
-) I added many test cases which also test all the negative scenarios (where the optimization should bail).
-) If it still turns out that there is a problem, this optimization pass can be easily disabled with a command line option

Reviewed by: @atrick, @gottesmm and @swiftix

Jira/Radar: SR-5508, rdar://problem/33404490

This is a separate optimization that detects short-lived temporaries that can be eliminated.
This is necessary now that SILGen no longer performs basic RValue forwarding in some cases.

SR-5508: Performance regression in benchmarks caused by removing SILGen peephole for LoadExpr in +0 context
@eeckstein
Copy link
Contributor Author

@swift-ci Please test

2 similar comments
@eeckstein
Copy link
Contributor Author

@swift-ci Please test

@shahmishal
Copy link
Member

@swift-ci Please test

@rjmccall
Copy link
Contributor

rjmccall commented Aug 7, 2017

This shouldn't hold up the 4.0 fix, but: you say that in some cases we end up copying the whole struct value when it was not copied in the original source. Is it possible that the LoadExpr is simply being applied at too coarse a level, i.e. that the type-checker is producing Project(Load(x)) instead of Load(Project(x))? Because we may be able to fix that in a fairly direct way without breaking ownership rules, either by changing CSApply or by changing SILGen to peephole that.

@eeckstein eeckstein merged commit fc0e839 into swiftlang:swift-4.0-branch Aug 7, 2017
@eeckstein eeckstein deleted the copyprop-4.0 branch August 9, 2017 22:07
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.

3 participants