Skip to content
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

[DNM: Draft][SILOpt] TempRValueElimination: 'let' copy source values cant be over… #61502

Closed

Conversation

hyp
Copy link
Contributor

@hyp hyp commented Oct 8, 2022

…writen by apply instructions

TempRValueElimination checks if a copy of a value can be eliminated. Checking that the original source value was not modified during the copy is one of the requirements for the elimination. Prior to this change, TempRValueElimination checked if apply instructions could've potentially modified the original source value, even if the source value was an immutable 'let'. This prevented some optimization opportunities. With this change, we can recognize that 'let' source value won't be modified by an apply, so that we can proceed with copy elimination.

…writen by apply instructions

TempRValueElimination checks if a copy of a value can be eliminated. Checking that the original
source value was not modified during the copy is one of the requirements for the elimination.
Prior to this change, TempRValueElimination checked if apply instructions could've
potentially modified the original source value, even if the source value was an immutable 'let'.
This prevented some optimization opportunities. With this change, we can recognize that 'let'
source value won't be modified by an apply, so that we can proceed with copy elimination.
@hyp hyp added the SILOptimizer Area → compiler: SIL optimization passes label Oct 8, 2022
@hyp
Copy link
Contributor Author

hyp commented Oct 8, 2022

still needs tests

@hyp
Copy link
Contributor Author

hyp commented Oct 8, 2022

@swift-ci please benchmark

@hyp
Copy link
Contributor Author

hyp commented Oct 8, 2022

@swift-ci please test

if ((FullApplySite::isa(inst) || isa<YieldInst>(inst)) &&
aa->mayWriteToMemory(inst, copySrc)) {
!isLetObject(copySrc) && aa->mayWriteToMemory(inst, copySrc)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, you can just use bool swift::isLetAddress(SILValue address). That uses the canonical AccessBase utility. It's a bit less ad-hoc and you don't need to DIY.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meg-gupta pointed out that if you just check AllocStack::isLet() inside isLetAddress, then you shouldn't need to touch this pass at all.

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a .sil test to temp_rvalue_opt_ossa.sil?

@hyp
Copy link
Contributor Author

hyp commented Oct 8, 2022

Closing in favor of #61504

@hyp hyp closed this Oct 8, 2022
@atrick
Copy link
Contributor

atrick commented Oct 11, 2022

I think @meg-gupta will introduce a PR very similar to this, maybe with a comment that we can't safely rely on mayWriteToMemory to recognize 'let' variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SILOptimizer Area → compiler: SIL optimization passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants