Skip to content

Commit fe93682

Browse files
committed
RedundantPhiElimination: exclude allocation instructions.
Treating allocation instructions as the same value caused runtime crashes. https://bugs.swift.org/browse/SR-12606
1 parent 8996b9d commit fe93682

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/SILOptimizer/Transforms/RedundantPhiElimination.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ bool RedundantPhiEliminationPass::valuesAreEqual(SILValue val1, SILValue val2) {
175175
if (inst1->getMemoryBehavior() != SILInstruction::MemoryBehavior::None)
176176
return false;
177177

178+
// Allocation instructions are defined to have no side-effects.
179+
// Two allocations (even if the instruction look the same) don't define
180+
// the same value.
181+
if (isa<AllocationInst>(inst1))
182+
return false;
183+
178184
auto *inst2 = cast<SingleValueInstruction>(val2);
179185

180186
// Compare the operands by putting them on the worklist.

test/SILOptimizer/redundant_phi_elimination.sil

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ sil_stage canonical
55
import Builtin
66
import Swift
77

8+
class X {}
9+
810
// CHECK-LABEL: sil @test_simple
911
// CHECK: bb1:
1012
// CHECK: br bb3(%0 : $Builtin.Int64)
@@ -153,3 +155,21 @@ bb3:
153155
%r = tuple ()
154156
return %r : $()
155157
}
158+
159+
// CHECK-LABEL: sil @test_allocation_inst
160+
// CHECK: alloc_ref
161+
// CHECK: alloc_ref
162+
// CHECK: bb1([[ARG1:%[0-9]+]] : $X, [[ARG2:%[0-9]+]] : $X):
163+
// CHECK: tuple ([[ARG1]] : $X, [[ARG2]] : $X)
164+
// CHECK: } // end sil function 'test_allocation_inst'
165+
sil @test_allocation_inst : $@convention(thin) () -> (X, X) {
166+
bb0:
167+
%1 = alloc_ref $X
168+
%2 = alloc_ref $X
169+
br bb1(%1 : $X, %2 : $X)
170+
171+
bb1(%3 : $X, %4 : $X):
172+
%r = tuple (%3 : $X, %4 : $X)
173+
return %r : $(X, X)
174+
}
175+

0 commit comments

Comments
 (0)