mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
For example: hoist out of loops where the loop count could be 0. We did this on purpose. But, if not wrong, it's at least very confusing if the initializer has observable side effects. Instead let CSE and LICM do the job and handle initializer side-effects correctly. rdar://problem/60292679
56 lines
2.1 KiB
Plaintext
56 lines
2.1 KiB
Plaintext
// 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 @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 %1 : $*Int64
|
|
%5 = tuple ()
|
|
return %5 : $()
|
|
}
|
|
|
|
sil hidden [global_init] @$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 @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 @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 %7 : $*Int64
|
|
end_access %7 : $*Int64
|
|
%33 = begin_access [read] [dynamic] [no_nested_conflict] %4 : $*Int64
|
|
%35 = load %33 : $*Int64
|
|
end_access %33 : $*Int64
|
|
return %35 : $Int64
|
|
}
|
|
|