Skip to content

Commit 93e5701

Browse files
committed
[AddressLowering] Rewrite uses of rewritten def.
During def rewriting, the def itself can be changed, for example to be a "dummy" load. In such cases, uses of the new def need to be rewritten, not uses of the original def.
1 parent 06cf796 commit 93e5701

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3377,6 +3377,9 @@ static void rewriteFunction(AddressLoweringState &pass) {
33773377
DefRewriter::rewriteValue(valueDef, pass);
33783378
valueAndStorage.storage.markRewritten();
33793379
}
3380+
// The def of interest may have been changed by rewriteValue. Get that
3381+
// redefinition back out of the ValueStoragePair.
3382+
valueDef = valueAndStorage.value;
33803383
// Rewrite a use of any non-address value mapped to storage (does not
33813384
// include the already rewritten uses of indirect arguments).
33823385
if (valueDef->getType().isAddress())

test/SILOptimizer/address_lowering.sil

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,28 @@ nopers(%error : @owned $any Error):
12661266
throw %error : $any Error
12671267
}
12681268

1269+
// CHECK-LABEL: sil [ossa] @f262_testTryApplyIntoPhi : {{.*}} {
1270+
// CHECK: {{bb[0-9]+}}([[ADDR:%[^,]+]] :
1271+
// CHECK: try_apply undef<R>([[ADDR]]) {{.*}}, normal [[NORMAL:bb[0-9]+]]
1272+
// CHECK: [[NORMAL]](%2 : $()):
1273+
// CHECK: br [[EXIT:bb[0-9]+]]
1274+
// CHECK: [[EXIT]]:
1275+
// CHECK: return {{%[^,]+}} : $()
1276+
// CHECK-LABEL: } // end sil function 'f262_testTryApplyIntoPhi'
1277+
sil [ossa] @f262_testTryApplyIntoPhi : $@convention(thin) <R> () -> (@out R, @error any Error) {
1278+
entry:
1279+
try_apply undef<R>() : $@convention(thin) <U> () -> (@out U, @error any Error), normal good, error bad
1280+
1281+
good(%instance : @owned $R):
1282+
br exit(%instance : $R)
1283+
1284+
exit(%instance_2 : @owned $R):
1285+
return %instance_2 : $R
1286+
1287+
bad(%41 : @owned $any Error):
1288+
throw %41 : $any Error
1289+
}
1290+
12691291
// CHECK-LABEL: sil [ossa] @fixeeLifetime : {{.*}} {
12701292
// CHECK: {{bb[0-9]+}}([[ADDR:%[^,]+]] : $*T):
12711293
// CHECK: fix_lifetime [[ADDR]]

0 commit comments

Comments
 (0)