Skip to content

Commit 0ea5d05

Browse files
committed
Delete debug_value_addr of stack location, if a debug_value of the RunningVal is already found
1 parent 8347470 commit 0ea5d05

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,10 @@ promoteDebugValueAddr(DebugValueAddrInst *DVAI, SILValue Value, SILBuilder &B) {
323323
// Avoid inserting the same debug_value twice.
324324
for (Operand *Use : Value->getUses())
325325
if (auto *DVI = dyn_cast<DebugValueInst>(Use->getUser()))
326-
if (*DVI->getVarInfo() == *DVAI->getVarInfo())
326+
if (*DVI->getVarInfo() == *DVAI->getVarInfo()) {
327+
DVAI->eraseFromParent();
327328
return;
329+
}
328330
B.setInsertionPoint(DVAI);
329331
B.setCurrentDebugScope(DVAI->getDebugScope());
330332
B.createDebugValue(DVAI->getLoc(), Value, *DVAI->getVarInfo());

test/SILOptimizer/mem2reg_ossa_nontrivial.sil

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,3 +613,20 @@ bb0(%0 : @owned $(Builtin.BridgeObject, Builtin.Int32)):
613613
%7 = tuple ()
614614
return %7 : $()
615615
}
616+
617+
// CHECK-LABEL: sil [ossa] @multiple_debug_value :
618+
// CHECK-NOT: alloc_stack
619+
// CHECK-LABEL: } // end sil function 'multiple_debug_value'
620+
sil [ossa] @multiple_debug_value : $@convention(thin) (@owned Klass) -> () {
621+
bb0(%0 : @owned $Klass):
622+
debug_value %0 : $Klass
623+
%2 = alloc_stack $Klass
624+
store %0 to [init] %2 : $*Klass
625+
debug_value_addr %2 : $*Klass
626+
%5 = load [take] %2 : $*Klass
627+
destroy_value %5 : $Klass
628+
dealloc_stack %2 : $*Klass
629+
%7 = tuple ()
630+
return %7 : $()
631+
}
632+

0 commit comments

Comments
 (0)