Skip to content

Commit 02c28f5

Browse files
committed
[AllocBoxToStack] Drop dead_end dealloc_boxes.
When creating `dealloc_stack`s corresponding to `dealloc_box`es, don't bother to create a dealloc_stack if the `dealloc_box` is flagged `dead_end`.
1 parent 1d47d3c commit 02c28f5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/SILOptimizer/Transforms/AllocBoxToStack.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,11 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
709709
// instruction we found that isn't an explicit dealloc_box.
710710
Builder.emitDestroyAddrAndFold(Loc, valueToDestroy);
711711
}
712+
auto *dbi = dyn_cast<DeallocBoxInst>(LastRelease);
713+
if (dbi && dbi->isDeadEnd()) {
714+
// Don't bother to create dealloc_stack instructions in dead-ends.
715+
continue;
716+
}
712717
Builder.createDeallocStack(Loc, ASI);
713718
}
714719

test/SILOptimizer/allocbox_to_stack_lifetime.sil

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,24 @@ bb0(%0 : $Int):
5050
return %3 : $Int
5151
}
5252

53+
// CHECK-LABEL: sil [ossa] @keep_dead_end : {{.*}} {
54+
// CHECK: [[STACK:%[^,]+]] = alloc_stack
55+
// CHECK: cond_br undef, [[DIE:bb[0-9]+]]
56+
// CHECK: [[DIE]]:
57+
// CHECK-NEXT: unreachable
58+
// CHECK-LABEL: } // end sil function 'keep_dead_end'
59+
sil [ossa] @keep_dead_end : $@convention(thin) () -> () {
60+
bb0:
61+
%b = alloc_box ${ var Int }
62+
cond_br undef, die, exit
63+
64+
die:
65+
dealloc_box [dead_end] %b : ${ var Int }
66+
unreachable
67+
68+
exit:
69+
dealloc_box %b : ${ var Int }
70+
%retval = tuple ()
71+
return %retval : $()
72+
73+
}

0 commit comments

Comments
 (0)