File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -505,6 +505,15 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *ASI) {
505
505
break ;
506
506
}
507
507
}
508
+
509
+ // Remove dead address instructions that may be uses of the allocation.
510
+ while (Inst->use_empty () && (isa<StructElementAddrInst>(Inst) ||
511
+ isa<TupleElementAddrInst>(Inst))) {
512
+ SILValue Next = Inst->getOperand (0 );
513
+ Inst->eraseFromParent ();
514
+ NumInstRemoved++;
515
+ Inst = cast<SILInstruction>(Next);
516
+ }
508
517
}
509
518
}
510
519
Original file line number Diff line number Diff line change @@ -327,3 +327,18 @@ bb0(%0 : $AnyObject):
327
327
return %7 : $()
328
328
}
329
329
330
+ // Test cases where there are dead address instructions.
331
+ // CHECK-LABEL: sil @dead_use
332
+ // CHECK-NOT: alloc_stack
333
+ sil @dead_use : $@convention(thin) () -> () {
334
+ %0 = alloc_stack $Int64
335
+ %1 = struct_element_addr %0 : $*Int64, #Int64._value
336
+ dealloc_stack %0 : $*Int64
337
+ %2 = alloc_stack $(Int64, Int64)
338
+ %3 = tuple_element_addr %2 : $*(Int64, Int64), 0
339
+ dealloc_stack %2 : $*(Int64, Int64)
340
+ // CHECK: [[VAL:%.*]] = tuple ()
341
+ %4 = tuple ()
342
+ // CHECK: return [[VAL]]
343
+ return %4 : $()
344
+ }
You can’t perform that action at this time.
0 commit comments