Skip to content

Commit abd1603

Browse files
committed
TempLValueOpt : Cleanup debug_value_addr when combining a copy_addr and destroy
1 parent 7a434a3 commit abd1603

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/SILOptimizer/Transforms/TempLValueOpt.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,23 @@ bool TempLValueOptPass::combineCopyAndDestroy(CopyAddrInst *copyInst) {
279279

280280
// Check if the destroy_addr is after the copy_addr and if there are no
281281
// memory accesses between them.
282+
SmallVector<DebugValueAddrInst *, 4> debugInsts;
282283
for (auto iter = std::next(copyInst->getIterator());
283284
iter != block->end(); ++iter) {
284285
SILInstruction *inst = &*iter;
285286
if (inst == destroy) {
286287
copyInst->setIsTakeOfSrc(IsTake);
287288
destroy->eraseFromParent();
289+
// Cleanup all debug_value_addr of the copy src btw the copy and destroy
290+
for (auto debugInst : debugInsts) {
291+
debugInst->eraseFromParent();
292+
}
288293
return true;
289294
}
295+
if (auto *debugInst = dyn_cast<DebugValueAddrInst>(inst)) {
296+
if (debugInst->getOperand() == copyInst->getSrc())
297+
debugInsts.push_back(debugInst);
298+
}
290299
if (inst->mayReadOrWriteMemory())
291300
return false;
292301
}

test/SILOptimizer/templvalueopt_ossa.sil

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,21 @@ bb0(%0 :@owned $Child):
282282
%res = tuple ()
283283
return %res : $()
284284
}
285+
286+
// CHECK-LABEL: sil [ossa] @cleanup_debuginsts :
287+
// CHECK: copy_addr [take]
288+
// CHECK-NOT: debug_value_addr
289+
// CHECK-LABEL: } // end sil function 'cleanup_debuginsts'
290+
sil [ossa] @cleanup_debuginsts : $@convention(thin) <T> (@in T) -> () {
291+
bb0(%0 : $*T):
292+
%2 = alloc_stack $T
293+
debug_value_addr %0 : $*T
294+
copy_addr %0 to [initialization] %2 : $*T
295+
debug_value_addr %0 : $*T
296+
destroy_addr %0 : $*T
297+
destroy_addr %2 : $*T
298+
dealloc_stack %2 : $*T
299+
%78 = tuple ()
300+
return %78 : $()
301+
}
302+

0 commit comments

Comments
 (0)