|
| 1 | +// RUN: %target-sil-opt -enable-sil-verify-all -sroa %s -enable-experimental-lexical-lifetimes | %FileCheck %s |
| 2 | + |
| 3 | +sil_stage canonical |
| 4 | + |
| 5 | +import Builtin |
| 6 | +import Swift |
| 7 | + |
| 8 | +/////////////////////////////// |
| 9 | +// Struct with Scalar Fields // |
| 10 | +/////////////////////////////// |
| 11 | + |
| 12 | +struct S1 { |
| 13 | + var x : Builtin.Int1 |
| 14 | + var y : Builtin.Int32 |
| 15 | + var z : Builtin.Int64 |
| 16 | +} |
| 17 | + |
| 18 | +sil [ossa] @use_int32 : $@convention(thin) (Builtin.Int32) -> () |
| 19 | + |
| 20 | +// CHECK-LABEL: sil [ossa] @struct_with_scalar_fields : $@convention(thin) (S1) -> () |
| 21 | +// CHECK: bb0([[VAR_0:%[0-9]+]] : $S1): |
| 22 | + |
| 23 | +// CHECK-NEXT: [[VAR_1:%[0-9]+]] = alloc_stack [lexical] $Builtin.Int1 |
| 24 | +// CHECK-NEXT: [[VAR_2:%[0-9]+]] = alloc_stack [lexical] $Builtin.Int32 |
| 25 | +// CHECK-NEXT: [[VAR_3:%[0-9]+]] = alloc_stack [lexical] $Builtin.Int64 |
| 26 | +// CHECK-NEXT: ([[VAR_4:%[0-9]+]], [[VAR_6:%[0-9]+]], [[VAR_8:%[0-9]+]]) = destructure_struct [[VAR_0]] |
| 27 | +// CHECK-NEXT: store [[VAR_4]] to [trivial] [[VAR_1]] : $*Builtin.Int1 |
| 28 | +// CHECK-NEXT: store [[VAR_6]] to [trivial] [[VAR_2]] : $*Builtin.Int32 |
| 29 | +// CHECK-NEXT: store [[VAR_8]] to [trivial] [[VAR_3]] : $*Builtin.Int64 |
| 30 | + |
| 31 | +// CHECK-NEXT: function_ref |
| 32 | +// CHECK-NEXT: [[VAR_10:%[0-9]+]] = function_ref @use_int32 : $@convention(thin) (Builtin.Int32) -> () |
| 33 | +// CHECK-NEXT: [[VAR_11:%[0-9]+]] = load [trivial] [[VAR_2]] : $*Builtin.Int32 |
| 34 | +// CHECK-NEXT: [[VAR_12:%[0-9]+]] = apply [[VAR_10]]([[VAR_11]]) : $@convention(thin) (Builtin.Int32) -> () |
| 35 | +// CHECK-NEXT: [[VAR_13:%[0-9]+]] = load [trivial] [[VAR_1]] : $*Builtin.Int1 |
| 36 | +// CHECK-NEXT: [[VAR_14:%[0-9]+]] = load [trivial] [[VAR_2]] : $*Builtin.Int32 |
| 37 | +// CHECK-NEXT: [[VAR_15:%[0-9]+]] = load [trivial] [[VAR_3]] : $*Builtin.Int64 |
| 38 | +// CHECK-NEXT: [[VAR_16:%[0-9]+]] = struct $S1 ([[VAR_13]] : $Builtin.Int1, [[VAR_14]] : $Builtin.Int32, [[VAR_15]] : $Builtin.Int64) |
| 39 | + |
| 40 | +// CHECK: dealloc_stack [[VAR_3]] : $*Builtin.Int64 |
| 41 | +// CHECK: dealloc_stack [[VAR_2]] : $*Builtin.Int32 |
| 42 | +// CHECK: dealloc_stack [[VAR_1]] : $*Builtin.Int1 |
| 43 | + |
| 44 | +// CHECK: [[VAR_20:%[0-9]+]] = tuple () |
| 45 | +// CHECK: return [[VAR_20]] : $() |
| 46 | +sil [ossa] @struct_with_scalar_fields : $@convention(thin) (S1) -> () { |
| 47 | +bb0(%0 : $S1): |
| 48 | + %1 = alloc_stack [lexical] $S1 |
| 49 | + debug_value %1 : $*S1 // should not prevent the optimization |
| 50 | + debug_value %1 : $*S1 // should not prevent the optimization |
| 51 | + store %0 to [trivial] %1 : $*S1 |
| 52 | + %2 = function_ref @use_int32 : $@convention(thin) (Builtin.Int32) -> () |
| 53 | + %3 = struct_element_addr %1 : $*S1, #S1.y |
| 54 | + %4 = load [trivial] %3 : $*Builtin.Int32 |
| 55 | + apply %2(%4) : $@convention(thin) (Builtin.Int32) -> () |
| 56 | + %5 = load [trivial] %1 : $*S1 |
| 57 | + dealloc_stack %1 : $*S1 |
| 58 | + %6 = tuple () |
| 59 | + return %6 : $() |
| 60 | +} |
| 61 | + |
0 commit comments