Skip to content

Commit 3addadc

Browse files
authored
Merge pull request #79766 from meg-gupta/fixmem2reg
Fix mem2reg for load_borrows with reborrows
2 parents 375bc35 + 4c46faa commit 3addadc

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,6 @@ static bool isLoadFromStack(SILInstruction *i, AllocStackInst *asi) {
377377
if (!isa<LoadInst>(i) && !isa<LoadBorrowInst>(i))
378378
return false;
379379

380-
if (auto *lbi = dyn_cast<LoadBorrowInst>(i)) {
381-
if (BorrowedValue(lbi).hasReborrow())
382-
return false;
383-
}
384-
385380
// Skip struct and tuple address projections.
386381
ValueBase *op = i->getOperand(0);
387382
while (op != asi) {

test/SILOptimizer/mem2reg_borrows.sil

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,30 @@ bb6:
408408
%17 = tuple ()
409409
return %17 : $()
410410
}
411+
412+
// CHECK-LABEL: sil [ossa] @test_load_borrow_with_reborrow :
413+
// CHECK-NOT: alloc_stack
414+
// CHECK-LABEL: } // end sil function 'test_load_borrow_with_reborrow'
415+
sil [ossa] @test_load_borrow_with_reborrow : $@convention(thin) () -> () {
416+
bb0:
417+
%owned = apply undef() : $@convention(thin) () -> (@owned Klass)
418+
%stack = alloc_stack [lexical] $Klass
419+
store %owned to [init] %stack : $*Klass
420+
br bb1
421+
422+
bb1:
423+
%ld = load [take] %stack : $*Klass
424+
destroy_value %ld
425+
%owned_other = apply undef() : $@convention(thin) () -> (@owned Klass)
426+
store %owned_other to [init] %stack : $*Klass
427+
%lb = load_borrow %stack
428+
br bb2(%lb)
429+
430+
bb2(%reborrow : @reborrow $Klass):
431+
end_borrow %reborrow : $Klass
432+
destroy_addr %stack : $*Klass
433+
dealloc_stack %stack : $*Klass
434+
%retval = tuple ()
435+
return %retval : $()
436+
}
437+

0 commit comments

Comments
 (0)