1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17public class Main {
18
19  static class Foo {
20    int field0;
21    int field1;
22    int field2;
23    int field3;
24    int field4;
25  };
26
27  /// CHECK-START: void Main.test1(boolean, int, int, int, int, int) register (after)
28  /// CHECK:       name "B0"
29  /// CHECK-NOT:     ParallelMove
30  /// CHECK:       name "B1"
31  /// CHECK-NOT:   end_block
32  /// CHECK:         If
33  /// CHECK-NOT:     ParallelMove
34  /// CHECK:       name "B3"
35  /// CHECK-NOT:   end_block
36  /// CHECK:         InstanceFieldSet
37  // We could check here that there is a parallel move, but it's only valid
38  // for some architectures (for example x86), as other architectures may
39  // not do move at all.
40  /// CHECK:       end_block
41  /// CHECK-NOT:     ParallelMove
42
43  public static void test1(boolean z, int a, int b, int c, int d, int m) {
44    int e = live1;
45    int f = live2;
46    int g = live3;
47    int j = live0;
48    if (z) {
49    } else {
50      // Create enough live instructions to force spilling on x86.
51      int h = live4;
52      int i = live5;
53      foo.field2 = e + i + h;
54      foo.field3 = f + i + h;
55      foo.field4 = g + i + h;
56      foo.field0 = h;
57      foo.field1 = i + h;
58    }
59    live1 = e + f + g + j;
60  }
61
62  /// CHECK-START: void Main.test2(boolean, int, int, int, int, int) register (after)
63  /// CHECK:       name "B0"
64  /// CHECK-NOT:     ParallelMove
65  /// CHECK:       name "B1"
66  /// CHECK-NOT:   end_block
67  /// CHECK:         If
68  /// CHECK-NOT:     ParallelMove
69  /// CHECK:       name "B3"
70  /// CHECK-NOT:   end_block
71  /// CHECK:         InstanceFieldSet
72  // We could check here that there is a parallel move, but it's only valid
73  // for some architectures (for example x86), as other architectures may
74  // not do move at all.
75  /// CHECK:       end_block
76  /// CHECK-NOT:     ParallelMove
77
78  public static void test2(boolean z, int a, int b, int c, int d, int m) {
79    int e = live1;
80    int f = live2;
81    int g = live3;
82    int j = live0;
83    if (z) {
84      if (y) {
85        int h = live4;
86        int i = live5;
87        foo.field2 = e + i + h;
88        foo.field3 = f + i + h;
89        foo.field4 = g + i + h;
90        foo.field0 = h;
91        foo.field1 = i + h;
92      }
93    }
94    live1 = e + f + g + j;
95  }
96
97  /// CHECK-START: void Main.test3(boolean, int, int, int, int, int) register (after)
98  /// CHECK:       name "B0"
99  /// CHECK-NOT:     ParallelMove
100  /// CHECK:       name "B1"
101  public static void test3(boolean z, int a, int b, int c, int d, int m) {
102    // Same version as test2, but with branches reversed, to ensure
103    // whatever linear order is computed, we will get the same results.
104    int e = live1;
105    int f = live2;
106    int g = live3;
107    int j = live0;
108    if (z) {
109      live1 = e;
110    } else {
111      if (y) {
112        live1 = e;
113      } else {
114        int h = live4;
115        int i = live5;
116        foo.field2 = e + i + h;
117        foo.field3 = f + i + h;
118        foo.field4 = g + i + h;
119        foo.field0 = h;
120        foo.field1 = i + h;
121      }
122    }
123    live1 = e + f + g + j;
124  }
125
126  public static void main(String[] args) {
127  }
128
129  static boolean y;
130  static int live0;
131  static int live1;
132  static int live2;
133  static int live3;
134  static int live4;
135  static int live5;
136  static Foo foo;
137}
138