TempRValueOpt: small fixes/improvements for extending access scopes

Don't move an end_access over a (non-aliasing) end_access. This would destroy the proper nesting of accesses.
Also, add some comments, asserts and tests.
This commit is contained in:
Erik Eckstein
2021-03-24 12:51:30 +01:00
parent 67ce72cebb
commit 9b16a94e8d
2 changed files with 56 additions and 4 deletions

View File

@@ -367,19 +367,27 @@ bool TempRValueOptPass::extendAccessScopes(
for (SILInstruction &inst : make_range(begin, end)) {
if (auto *endAccess = dyn_cast<EndAccessInst>(&inst)) {
// To keep things simple, we can just move a single end_access. Also, we
// cannot move an end_access over a (non-aliasing) end_access.
if (endAccessToMove)
return false;
// Is this the end of an access scope of the copy-source?
if (!aa->isNoAlias(copySrc, endAccess->getSource())) {
// To keep things simple, we can just move a single end_access.
if (endAccessToMove)
return false;
assert(endAccess->getBeginAccess()->getAccessKind() ==
SILAccessKind::Read &&
"a may-write end_access should not be in the copysrc lifetime");
endAccessToMove = endAccess;
}
} else if (endAccessToMove) {
// We cannot move an end_access over a begin_access. This would destroy
// the proper nesting of accesses.
if (isa<BeginAccessInst>(&inst))
if (isa<BeginAccessInst>(&inst) || isa<BeginUnpairedAccessInst>(inst))
return false;
// Don't extend a read-access scope over a (potential) write.
// Note that inst can be a function call containing other access scopes.
// But doing the mayWriteToMemory check, we know that the function can
// only contain read accesses (to the same memory location). So it's fine
// to move endAccessToMove even over such a function call.
if (aa->mayWriteToMemory(&inst, endAccessToMove->getSource()))
return false;
}