-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[TempRValueOpt] Fold added destroy_addrs into loads/copy_addrs. #65052
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
586bf88
to
5ca36e0
Compare
@swift-ci please test |
@swift-ci please benchmark |
@swift-ci please test source compatibility |
Source compat failures match baseline. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
li->getOwnershipQualifier() != LoadOwnershipQualifier::Take; | ||
} | ||
return true; | ||
}(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can add an assert here to check if it's a move only type then needToInsertDestroy
must be false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added asserts along those lines in 1021519 . (Along with a test illustrating why needToInsertDestroy
might be true even when the type is move-only--if lastLoadInst
is an apply.)
In preparation for "folding" an "inserted destroy" into a load [copy] or copy_addr, rename the variable that indicates whether the copyInst's source must be deinitialized after its last "load".
As a separate commit to make the behavior change more obvious.
To avoid introducing new copies--which is illegal for move-only values-- don't rewrite `load [take]`s and `copy_addr [take]`s as `load [copy]`s and `copy_addr`s respectively and introduce new `destroy_addr`s after them. Instead, get the effect of folding such a newly created `destroy_addr` into the preceding rewritten `load [copy]` or `copy_addr`. Get that effect by neither modifying the `copy_addr [take]` or `load [take]` nor adding a subsequent `destroy_addr`. An example for each kind (`load [take]` and `copy_addr [take]`): ``` // Input 1 (`load [take]`) copy_addr [take] %src to [init] %tmp %val = load [take] %src // Old Output 1 %val = load [copy] %src destroy_addr %src // New Output 2 %val = load [take] %src ``` ``` // Input 2 (`copy_addr [take]`) copy_addr [take] %src to [init] %tmp copy_addr [take] %src to [init] %dst // Old Output 2 copy_addr %src to [init] %dst destroy_addr %src // New Output 2 copy_addr [take] %src to [init] %dst ``` rdar://107839979
5ca36e0
to
1021519
Compare
@swift-ci please test and merge |
@swift-ci please test linux platform |
@swift-ci please test macOS platform |
@swift-ci please test linux platform |
if (lastLoadInst == copyInst) | ||
return true; | ||
if (auto *cai = dyn_cast<CopyAddrInst>(lastLoadInst)) { | ||
auto retval = cai->getSrc() != tempObj || !cai->isTakeOfSrc(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: all these conditions are getting hard to understand. IMO, for clarity it's better to write
if (cai->getSrc() == tempObj && cai->isTakeOfSrc()) {
// Can reuse the last copy_addr as deinitialization.
return false;
} else {
assert(!tempObj->getType().isMoveOnly() && "introducing copy of move-only value!?");
return true;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid introducing new copies--which is illegal for move-only values-- don't rewrite
load [take]
s andcopy_addr [take]
s asload [copy]
s andcopy_addr
s respectively and introduce newdestroy_addr
s after them. Instead, get the effect of folding such a newly createddestroy_addr
into the preceding rewrittenload [copy]
orcopy_addr
. Get that effect by neither modifying thecopy_addr [take]
orload [take]
nor adding a subsequentdestroy_addr
.An example for each kind (
load [take]
andcopy_addr [take]
):rdar://107839979