Skip to content

Commit fd9ba4e

Browse files
authored
Merge pull request #6988 from bob-wilson/mem2reg-fix-3.1
Fix an assertion failure in SILMem2Reg.
2 parents b8526ce + 454d8f1 commit fd9ba4e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,15 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *ASI) {
505505
break;
506506
}
507507
}
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+
}
508517
}
509518
}
510519

test/SILOptimizer/mem2reg.sil

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,18 @@ bb0(%0 : $AnyObject):
327327
return %7 : $()
328328
}
329329

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+
}

0 commit comments

Comments
 (0)