Skip to content

Commit 16b0f2c

Browse files
authored
Merge pull request #69886 from eeckstein/fix-predictable-memopt
PredictableMemOpt: fix wrong handling of re-borrows of a load_borrow
2 parents 6ccbd8b + c551ae0 commit 16b0f2c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,6 +2177,12 @@ bool AllocOptimize::promoteLoadBorrow(LoadBorrowInst *lbi) {
21772177
if (!result.has_value())
21782178
return false;
21792179

2180+
// Bail if the load_borrow has reborrows. In this case it's not so easy to
2181+
// find the insertion points for the destroys.
2182+
if (!lbi->getUsersOfType<BranchInst>().empty()) {
2183+
return false;
2184+
}
2185+
21802186
++NumLoadPromoted;
21812187

21822188
SILType loadTy = result->first;

test/SILOptimizer/predictable_memopt_ownership.sil

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,25 @@ bbEnd(%8 : @owned $Optional<Builtin.NativeObject>):
13411341
return %8 : $Optional<Builtin.NativeObject>
13421342
}
13431343

1344+
// CHECK-LABEL: sil [ossa] @dont_promote_load_borrow_with_reborrows :
1345+
// CHECK: load_borrow
1346+
// CHECK: } // end sil function 'dont_promote_load_borrow_with_reborrows'
1347+
sil [ossa] @dont_promote_load_borrow_with_reborrows : $@convention(thin) (@owned SomeClass) -> () {
1348+
bb0(%0 : @owned $SomeClass):
1349+
%1 = alloc_stack $SomeClass
1350+
store %0 to [init] %1 : $*SomeClass
1351+
%3 = load_borrow %1 : $*SomeClass
1352+
br bb1(%3 : $SomeClass)
1353+
1354+
bb1(%5 : @reborrow @guaranteed $SomeClass):
1355+
end_borrow %5 : $SomeClass
1356+
destroy_addr %1 : $*SomeClass
1357+
dealloc_stack %1 : $*SomeClass
1358+
%9 = tuple ()
1359+
return %9 : $()
1360+
}
1361+
1362+
13441363
class Foo {}
13451364
struct MyInt {
13461365
var _value: Builtin.Int64

0 commit comments

Comments
 (0)