Skip to content

Commit 8575923

Browse files
committed
Prevent sinkAddressProjections from creating phis of type Builtin.SILToken
Fixes rdar://121485860
1 parent 24814c5 commit 8575923

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

lib/SILOptimizer/Utils/BasicBlockOptUtils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ bool SinkAddressProjections::analyzeAddressProjections(SILInstruction *inst) {
231231
if (def->getParentBlock() != bb)
232232
return true;
233233

234+
if (def->getType().is<SILTokenType>()) {
235+
return false;
236+
}
237+
234238
if (!def->getType().isAddress()) {
235239
inBlockDefs.insert(def);
236240
return true;

test/SILOptimizer/simplify_cfg_ossa_jump_threading.sil

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,49 @@ bb4:
229229
destroy_value %4 : $FakeOptional<Klass>
230230
return %5 : $Builtin.Int1
231231
}
232+
233+
sil_global @my_global : $S
234+
235+
sil @globalinit_func11 : $@convention(thin) () -> ()
236+
237+
struct S {
238+
}
239+
240+
// This test is not optimized because the dest bb of the branch has a single predecessor
241+
// CHECK-LABEL: sil [ossa] @test_simplify_switch_enum_jump_threading_sil_token :
242+
// CHECK: switch_enum
243+
// CHECK-NOT: switch_enum
244+
// CHECK-LABEL: } // end sil function 'test_simplify_switch_enum_jump_threading_sil_token'
245+
sil [ossa] @test_simplify_switch_enum_jump_threading_sil_token : $@convention(thin) (@owned Klass, Builtin.RawPointer) -> () {
246+
bb0(%0 : @owned $Klass, %1 : $Builtin.RawPointer):
247+
cond_br undef, bb1, bb2
248+
249+
bb1:
250+
specify_test "simplify-cfg-try-jump-threading @instruction[2]"
251+
%s = enum $FakeOptional<Klass>, #FakeOptional.some!enumelt, %0 : $Klass
252+
br bb3(%s : $FakeOptional<Klass>)
253+
254+
bb2:
255+
destroy_value %0 : $Klass
256+
%n = enum $FakeOptional<Klass>, #FakeOptional.none!enumelt
257+
br bb3(%n : $FakeOptional<Klass>)
258+
259+
bb3(%3 : @owned $FakeOptional<Klass>):
260+
%f = function_ref @globalinit_func11 : $@convention(thin) () -> ()
261+
%b = builtin "once"(%1 : $Builtin.RawPointer, %f : $@convention(thin) () -> ()) : $Builtin.SILToken
262+
%g = global_addr @my_global : $*S depends_on %b
263+
switch_enum %3 : $FakeOptional<Klass>, case #FakeOptional.some!enumelt: bb5, case #FakeOptional.none!enumelt: bb4
264+
265+
bb4:
266+
br bb6
267+
268+
bb5(%6 : @owned $Klass):
269+
%ld = load [trivial] %g : $*S
270+
apply undef(%ld) : $@convention(thin) (S) -> ()
271+
destroy_value %6 : $Klass
272+
br bb6
273+
274+
bb6:
275+
%t = tuple ()
276+
return %t : $()
277+
}

0 commit comments

Comments
 (0)