Skip to content

Commit 81a4f7a

Browse files
committed
LetPropertyLowering: remove redundant phis after ssa-update
This is needed after running the SSAUpdater, because the updater can insert unnecessary phis in the middle of the original liverange of a value. Fixes an ownership error. rdar://153229472
1 parent 1a6ad0c commit 81a4f7a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LetPropertyLowering.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ private func insertEndInitInstructions(
122122
use.set(to: ssaUpdater.getValue(atEndOf: use.instruction.parentBlock), context)
123123
}
124124
}
125+
// This peephole optimization is required to avoid ownership errors.
126+
replacePhisWithIncomingValues(phis: ssaUpdater.insertedPhis, context)
125127
}
126128

127129
private func constructLetInitRegion(

test/SILOptimizer/let-property-lowering.sil

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,34 @@ bb1(%3a : @reborrow $C):
311311
return %2 : $C
312312
}
313313

314+
315+
// CHECK-LABEL: sil [ossa] @test_no_phis :
316+
// CHECK: %3 = end_init_let_ref %2
317+
// CHECK: return %3
318+
// CHECK: } // end sil function 'test_no_phis'
319+
sil [ossa] @test_no_phis : $@convention(thin) (Int, @owned C) -> @owned C {
320+
bb0(%0 : $Int, %1 : @owned $C):
321+
%2 = mark_uninitialized [rootself] %1
322+
%3 = begin_borrow %2
323+
cond_br undef, bb1, bb2
324+
bb1:
325+
br bb7
326+
bb2:
327+
cond_br undef, bb3, bb8
328+
bb3:
329+
cond_br undef, bb4, bb5
330+
bb4:
331+
br bb7
332+
bb5:
333+
br bb6
334+
bb6:
335+
end_borrow %3
336+
return %2
337+
bb7:
338+
br bb6
339+
bb8:
340+
end_borrow %3
341+
destroy_value [dead_end] %2
342+
unreachable
343+
}
344+

0 commit comments

Comments
 (0)