| // RUN: %target-sil-opt -enable-sil-verify-all %s -global-opt | %FileCheck %s |
| |
| sil_stage canonical |
| |
| import Builtin |
| import Swift |
| |
| private var testGlobal: Int64 |
| |
| sil_global private @globalinit_33_00F4D2139E6BDDFEC71E5005B67B5674_token0 : $Builtin.Word |
| |
| sil_global private @$s4test10testGlobalSivp : $Int64 |
| |
| sil private [ossa] @globalinit_33_00F4D2139E6BDDFEC71E5005B67B5674_func0 : $@convention(c) () -> () { |
| bb0: |
| alloc_global @$s4test10testGlobalSivp |
| %1 = global_addr @$s4test10testGlobalSivp : $*Int64 |
| %2 = integer_literal $Builtin.Int64, 27 |
| %3 = struct $Int64 (%2 : $Builtin.Int64) |
| store %3 to [trivial] %1 : $*Int64 |
| %5 = tuple () |
| return %5 : $() |
| } |
| |
| sil hidden [global_init] [ossa] @$s4test10testGlobalSivau : $@convention(thin) () -> Builtin.RawPointer { |
| bb0: |
| %0 = global_addr @globalinit_33_00F4D2139E6BDDFEC71E5005B67B5674_token0 : $*Builtin.Word |
| %1 = address_to_pointer %0 : $*Builtin.Word to $Builtin.RawPointer |
| %2 = function_ref @globalinit_33_00F4D2139E6BDDFEC71E5005B67B5674_func0 : $@convention(c) () -> () |
| %3 = builtin "once"(%1 : $Builtin.RawPointer, %2 : $@convention(c) () -> ()) : $() |
| %4 = global_addr @$s4test10testGlobalSivp : $*Int64 |
| %5 = address_to_pointer %4 : $*Int64 to $Builtin.RawPointer |
| return %5 : $Builtin.RawPointer |
| } |
| |
| // CHECK-LABEL: sil [ossa] @dont_propagate_global_with_multiple_writes |
| // CHECK: [[V:%[0-9]+]] = load |
| // CHECK: return [[V]] |
| // CHECK: } // end sil function 'dont_propagate_global_with_multiple_writes' |
| sil [ossa] @dont_propagate_global_with_multiple_writes : $@convention(thin) (Int64) -> Int64 { |
| bb0(%0 : $Int64): |
| %2 = function_ref @$s4test10testGlobalSivau : $@convention(thin) () -> Builtin.RawPointer |
| %3 = apply %2() : $@convention(thin) () -> Builtin.RawPointer |
| %4 = pointer_to_address %3 : $Builtin.RawPointer to [strict] $*Int64 |
| %5 = integer_literal $Builtin.Int64, 42 |
| %6 = struct $Int64 (%5 : $Builtin.Int64) |
| %7 = begin_access [modify] [dynamic] [no_nested_conflict] %4 : $*Int64 |
| store %6 to [trivial] %7 : $*Int64 |
| end_access %7 : $*Int64 |
| %33 = begin_access [read] [dynamic] [no_nested_conflict] %4 : $*Int64 |
| %35 = load [trivial] %33 : $*Int64 |
| end_access %33 : $*Int64 |
| return %35 : $Int64 |
| } |
| |