|
| 1 | +// RUN: %target-sil-opt -enable-sil-verify-all %s -global-opt | %FileCheck %s |
| 2 | + |
| 3 | +sil_stage canonical |
| 4 | + |
| 5 | +import Builtin |
| 6 | +import Swift |
| 7 | + |
| 8 | +private var testGlobal: Int64 |
| 9 | + |
| 10 | +sil_global private @globalinit_33_00F4D2139E6BDDFEC71E5005B67B5674_token0 : $Builtin.Word |
| 11 | + |
| 12 | +sil_global private @$s4test10testGlobalSivp : $Int64 |
| 13 | + |
| 14 | +sil private [ossa] @globalinit_33_00F4D2139E6BDDFEC71E5005B67B5674_func0 : $@convention(c) () -> () { |
| 15 | +bb0: |
| 16 | + alloc_global @$s4test10testGlobalSivp |
| 17 | + %1 = global_addr @$s4test10testGlobalSivp : $*Int64 |
| 18 | + %2 = integer_literal $Builtin.Int64, 27 |
| 19 | + %3 = struct $Int64 (%2 : $Builtin.Int64) |
| 20 | + store %3 to [trivial] %1 : $*Int64 |
| 21 | + %5 = tuple () |
| 22 | + return %5 : $() |
| 23 | +} |
| 24 | + |
| 25 | +sil hidden [global_init] [ossa] @$s4test10testGlobalSivau : $@convention(thin) () -> Builtin.RawPointer { |
| 26 | +bb0: |
| 27 | + %0 = global_addr @globalinit_33_00F4D2139E6BDDFEC71E5005B67B5674_token0 : $*Builtin.Word |
| 28 | + %1 = address_to_pointer %0 : $*Builtin.Word to $Builtin.RawPointer |
| 29 | + %2 = function_ref @globalinit_33_00F4D2139E6BDDFEC71E5005B67B5674_func0 : $@convention(c) () -> () |
| 30 | + %3 = builtin "once"(%1 : $Builtin.RawPointer, %2 : $@convention(c) () -> ()) : $() |
| 31 | + %4 = global_addr @$s4test10testGlobalSivp : $*Int64 |
| 32 | + %5 = address_to_pointer %4 : $*Int64 to $Builtin.RawPointer |
| 33 | + return %5 : $Builtin.RawPointer |
| 34 | +} |
| 35 | + |
| 36 | +// CHECK-LABEL: sil [ossa] @dont_propagate_global_with_multiple_writes |
| 37 | +// CHECK: [[V:%[0-9]+]] = load |
| 38 | +// CHECK: return [[V]] |
| 39 | +// CHECK: } // end sil function 'dont_propagate_global_with_multiple_writes' |
| 40 | +sil [ossa] @dont_propagate_global_with_multiple_writes : $@convention(thin) (Int64) -> Int64 { |
| 41 | +bb0(%0 : $Int64): |
| 42 | + %2 = function_ref @$s4test10testGlobalSivau : $@convention(thin) () -> Builtin.RawPointer |
| 43 | + %3 = apply %2() : $@convention(thin) () -> Builtin.RawPointer |
| 44 | + %4 = pointer_to_address %3 : $Builtin.RawPointer to [strict] $*Int64 |
| 45 | + %5 = integer_literal $Builtin.Int64, 42 |
| 46 | + %6 = struct $Int64 (%5 : $Builtin.Int64) |
| 47 | + %7 = begin_access [modify] [dynamic] [no_nested_conflict] %4 : $*Int64 |
| 48 | + store %6 to [trivial] %7 : $*Int64 |
| 49 | + end_access %7 : $*Int64 |
| 50 | + %33 = begin_access [read] [dynamic] [no_nested_conflict] %4 : $*Int64 |
| 51 | + %35 = load [trivial] %33 : $*Int64 |
| 52 | + end_access %33 : $*Int64 |
| 53 | + return %35 : $Int64 |
| 54 | +} |
| 55 | + |
0 commit comments