|
| 1 | +// RUN: %target-sil-opt -enable-sil-verify-all %s -onone-simplification -simplify-instruction=load | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ONONE |
| 2 | + |
| 3 | +// REQUIRES: swift_in_compiler |
| 4 | + |
| 5 | +import Swift |
| 6 | +import Builtin |
| 7 | + |
| 8 | +struct Str { |
| 9 | + @_hasStorage let x: Int64 |
| 10 | + @_hasStorage let y: (Int64, Int64) |
| 11 | +} |
| 12 | + |
| 13 | +sil_global [let] @gstr : $Str = { |
| 14 | + %0 = integer_literal $Builtin.Int64, 10 |
| 15 | + %1 = struct $Int64 (%0 : $Builtin.Int64) |
| 16 | + %2 = integer_literal $Builtin.Int64, 27 |
| 17 | + %3 = struct $Int64 (%2 : $Builtin.Int64) |
| 18 | + %4 = tuple (%1 : $Int64, %3 : $Int64) |
| 19 | + %initval = struct $Str (%1 : $Int64, %4 : $(Int64, Int64)) |
| 20 | +} |
| 21 | + |
| 22 | +sil [global_init] @gstr_addressor : $@convention(thin) () -> Builtin.RawPointer { |
| 23 | +bb0: |
| 24 | + %0 = global_addr @gstr : $*Str |
| 25 | + %1 = address_to_pointer %0 : $*Str to $Builtin.RawPointer |
| 26 | + return %1 : $Builtin.RawPointer |
| 27 | +} |
| 28 | + |
| 29 | +// CHECK-LABEL: sil @load_global_simple |
| 30 | +// CHECK-DAG: [[L27:%.*]] = integer_literal $Builtin.Int64, 27 |
| 31 | +// CHECK-DAG: [[I27:%.*]] = struct $Int64 ([[L27]] : $Builtin.Int64) |
| 32 | +// CHECK-DAG: [[L10:%.*]] = integer_literal $Builtin.Int64, 10 |
| 33 | +// CHECK-DAG: [[I10:%.*]] = struct $Int64 ([[L10]] : $Builtin.Int64) |
| 34 | +// CHECK-DAG: [[T:%.*]] = tuple ([[I10]] : $Int64, [[I27]] : $Int64) |
| 35 | +// CHECK: [[STR:%.*]] = struct $Str ([[I10]] : $Int64, [[T]] : $(Int64, Int64)) |
| 36 | +// CHECK: return [[STR]] |
| 37 | +// CHECK: } // end sil function 'load_global_simple' |
| 38 | +sil @load_global_simple : $@convention(thin) () -> Str { |
| 39 | +bb0: |
| 40 | + %0 = global_addr @gstr : $*Str |
| 41 | + %1 = begin_access [read] [static] %0 : $*Str |
| 42 | + %2 = load %1 : $*Str |
| 43 | + end_access %1 : $*Str |
| 44 | + return %2 : $Str |
| 45 | +} |
| 46 | + |
| 47 | +// CHECK-LABEL: sil @load_global_via_addressor |
| 48 | +// CHECK-NOT: apply |
| 49 | +// CHECK-DAG: [[L27:%.*]] = integer_literal $Builtin.Int64, 27 |
| 50 | +// CHECK-DAG: [[I27:%.*]] = struct $Int64 ([[L27]] : $Builtin.Int64) |
| 51 | +// CHECK-DAG: [[L10:%.*]] = integer_literal $Builtin.Int64, 10 |
| 52 | +// CHECK-DAG: [[I10:%.*]] = struct $Int64 ([[L10]] : $Builtin.Int64) |
| 53 | +// CHECK-DAG: [[T:%.*]] = tuple ([[I10]] : $Int64, [[I27]] : $Int64) |
| 54 | +// CHECK: [[STR:%.*]] = struct $Str ([[I10]] : $Int64, [[T]] : $(Int64, Int64)) |
| 55 | +// CHECK: return [[STR]] |
| 56 | +// CHECK: } // end sil function 'load_global_via_addressor' |
| 57 | +sil @load_global_via_addressor : $@convention(thin) () -> Str { |
| 58 | +bb0: |
| 59 | + %0 = function_ref @gstr_addressor : $@convention(thin) () -> Builtin.RawPointer |
| 60 | + %1 = apply %0() : $@convention(thin) () -> Builtin.RawPointer |
| 61 | + %2 = pointer_to_address %1 : $Builtin.RawPointer to [strict] $*Str |
| 62 | + %3 = load %2 : $*Str |
| 63 | + return %3 : $Str |
| 64 | +} |
| 65 | + |
| 66 | +// CHECK-LABEL: sil @load_global_struct_element |
| 67 | +// CHECK-NOT: global_addr |
| 68 | +// CHECK-DAG: [[L10:%.*]] = integer_literal $Builtin.Int64, 10 |
| 69 | +// CHECK-DAG: [[I10:%.*]] = struct $Int64 ([[L10]] : $Builtin.Int64) |
| 70 | +// CHECK: return [[I10]] |
| 71 | +// CHECK: } // end sil function 'load_global_struct_element' |
| 72 | +sil @load_global_struct_element : $@convention(thin) () -> Int64 { |
| 73 | +bb0: |
| 74 | + %0 = global_addr @gstr : $*Str |
| 75 | + %1 = struct_element_addr %0 : $*Str, #Str.x |
| 76 | + %2 = load %1 : $*Int64 |
| 77 | + return %2 : $Int64 |
| 78 | +} |
| 79 | + |
| 80 | +// CHECK-LABEL: sil @load_global_struct_tuple |
| 81 | +// CHECK-NOT: global_addr |
| 82 | +// CHECK-DAG: [[L27:%.*]] = integer_literal $Builtin.Int64, 27 |
| 83 | +// CHECK-DAG: [[I27:%.*]] = struct $Int64 ([[L27]] : $Builtin.Int64) |
| 84 | +// CHECK: return [[I27]] |
| 85 | +// CHECK: } // end sil function 'load_global_struct_tuple' |
| 86 | +sil @load_global_struct_tuple : $@convention(thin) () -> Int64 { |
| 87 | +bb0: |
| 88 | + %0 = global_addr @gstr : $*Str |
| 89 | + %1 = struct_element_addr %0 : $*Str, #Str.y |
| 90 | + %2 = tuple_element_addr %1 : $*(Int64, Int64), 1 |
| 91 | + %3 = load %2 : $*Int64 |
| 92 | + return %3 : $Int64 |
| 93 | +} |
| 94 | + |
0 commit comments