Skip to content

Commit 7cea31b

Browse files
committed
SILMem2Reg: Don't add dead values as phi arguments
A dealloc_stack ends the lifetime of an alloc_stack on a path. We don't have to pass RunningVal beyond the dealloc_stack as phi argument to the post dominating block.
1 parent 87f7097 commit 7cea31b

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,12 @@ StackAllocationPromoter::promoteAllocationInBlock(SILBasicBlock *BB) {
468468

469469
// Stop on deallocation.
470470
if (auto *DSI = dyn_cast<DeallocStackInst>(Inst)) {
471-
if (DSI->getOperand() == ASI)
471+
if (DSI->getOperand() == ASI) {
472+
// Reset LastStore.
473+
// So that we don't pass RunningVal as a phi arg beyond dealloc_stack
474+
LastStore = nullptr;
472475
break;
476+
}
473477
}
474478
}
475479
if (LastStore) {

test/SILOptimizer/mem2reg.sil

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,30 @@ bb0(%0 : $Optional<Klass>):
465465
%4 = tuple()
466466
return %4 : $()
467467
}
468+
469+
// CHECK-LABEL: sil @multi_basic_block_use_on_one_path :
470+
// CHECK-NOT: alloc_stack
471+
// CHECK:bb2:
472+
// CHECK: br bb3(undef : $Klass)
473+
// CHECK-LABEL: } // end sil function 'multi_basic_block_use_on_one_path'
474+
sil @multi_basic_block_use_on_one_path : $@convention(thin) (@owned Klass) -> () {
475+
bb0(%0 : $Klass):
476+
%1 = alloc_stack $Klass
477+
cond_br undef, bb1, bb2
478+
479+
bb1:
480+
dealloc_stack %1 : $*Klass
481+
strong_release %0 : $Klass
482+
br bb3
483+
484+
bb2:
485+
store %0 to %1 : $*Klass
486+
%7 = load %1 : $*Klass
487+
dealloc_stack %1 : $*Klass
488+
strong_release %7 : $Klass
489+
br bb3
490+
491+
bb3:
492+
%11 = tuple ()
493+
return %11 : $()
494+
}

0 commit comments

Comments
 (0)