Skip to content

Commit 71312fe

Browse files
authored
Merge pull request #61006 from meg-gupta/fixmem2regbug
Fix Mem2Reg check on end_borrows of store_borrow
2 parents 94910fa + b472301 commit 71312fe

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,9 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
18261826
if (!sbi) {
18271827
continue;
18281828
}
1829+
if (sbi->getDest() != asi) {
1830+
continue;
1831+
}
18291832
if (!runningVals.hasValue()) {
18301833
continue;
18311834
}

test/SILOptimizer/mem2reg_lifetime_borrows.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,28 @@ bb1:
501501
return %6 : $()
502502
}
503503

504+
// CHECK-LABEL: sil [ossa] @test_nested_sbi :
505+
// CHECK: alloc_stack
506+
// CHECK-NOT: alloc_stack [lexical]
507+
// CHECK-LABEL: } // end sil function 'test_nested_sbi'
508+
sil [ossa] @test_nested_sbi : $@convention(thin) (@guaranteed WrapperStruct) -> () {
509+
bb0(%0 : @guaranteed $WrapperStruct):
510+
%2 = alloc_stack [lexical] $WrapperStruct
511+
%3 = store_borrow %0 to %2 : $*WrapperStruct
512+
%6 = load_borrow %3 : $*WrapperStruct
513+
%7 = alloc_stack [lexical] $WrapperStruct
514+
%8 = store_borrow %6 to %7 : $*WrapperStruct
515+
%9 = struct_element_addr %8 : $*WrapperStruct, #WrapperStruct.val
516+
%16 = load_borrow %9 : $*Klass
517+
end_borrow %16 : $Klass
518+
end_borrow %8 : $*WrapperStruct
519+
dealloc_stack %7 : $*WrapperStruct
520+
end_borrow %6 : $WrapperStruct
521+
%27 = load_borrow %3 : $*WrapperStruct
522+
end_borrow %27 : $WrapperStruct
523+
end_borrow %3 : $*WrapperStruct
524+
dealloc_stack %2 : $*WrapperStruct
525+
%33 = tuple ()
526+
return %33 : $()
527+
}
528+

0 commit comments

Comments
 (0)