Skip to content

Commit 36fb073

Browse files
committed
OSSA RAUW prepareUnowned - short-circuit empty uses
Avoid generating useless empty copies and borrow scopes. Bypass all the use-checking logic when there are no uses to avoid special cases and bugs.
1 parent 652ff78 commit 36fb073

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/SILOptimizer/Utils/OwnershipOptUtils.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,13 @@ SILValue OwnershipRAUWPrepare::prepareUnowned(SILValue newValue) {
10611061

10621062
SILValue OwnershipRAUWPrepare::prepareReplacement(SILValue newValue) {
10631063
assert(oldValue->getFunction()->hasOwnership());
1064+
1065+
// A value with no uses can be "replaced" without fixup.
1066+
// (e.g. a dead no-ownership value can be replaced by an owned value even
1067+
// though hasValidRAUWOwnership will be false).
1068+
if (oldValue->use_empty())
1069+
return newValue;
1070+
10641071
assert(OwnershipRAUWHelper::hasValidRAUWOwnership(oldValue, newValue) &&
10651072
"Should have checked if can perform this operation before calling it?!");
10661073
// If our new value is just none, we can pass anything to it so just RAUW
@@ -1200,6 +1207,12 @@ OwnershipRAUWHelper::OwnershipRAUWHelper(OwnershipFixupContext &inputCtx,
12001207
// Clear the context before populating it anew.
12011208
ctx->clear();
12021209

1210+
// A value with no uses can be "replaced" regardless of its uses. Bypass all
1211+
// the use-checking logic, which assumes a non-empty use list.
1212+
if (oldValue->use_empty()) {
1213+
return;
1214+
}
1215+
12031216
// Otherwise, lets check if we can perform this RAUW operation. If we can't,
12041217
// set ctx to nullptr to invalidate the helper and return.
12051218
if (!canFixUpOwnershipForRAUW(oldValue, newValue, inputCtx)) {

0 commit comments

Comments
 (0)