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  /// CHECK-NOT:   end_block
102  /// CHECK:         If
103  /// CHECK-NOT:     ParallelMove
104  /// CHECK:       name "B6"
105  /// CHECK-NOT:   end_block
106  /// CHECK:         InstanceFieldSet
107  // We could check here that there is a parallel move, but it's only valid
108  // for some architectures (for example x86), as other architectures may
109  // not do move at all.
110  /// CHECK:       end_block
111  /// CHECK-NOT:     ParallelMove
112
113  public static void test3(boolean z, int a, int b, int c, int d, int m) {
114    // Same version as test2, but with branches reversed, to ensure
115    // whatever linear order is computed, we will get the same results.
116    int e = live1;
117    int f = live2;
118    int g = live3;
119    int j = live0;
120    if (z) {
121      live1 = e;
122    } else {
123      if (y) {
124        live1 = e;
125      } else {
126        int h = live4;
127        int i = live5;
128        foo.field2 = e + i + h;
129        foo.field3 = f + i + h;
130        foo.field4 = g + i + h;
131        foo.field0 = h;
132        foo.field1 = i + h;
133      }
134    }
135    live1 = e + f + g + j;
136  }
137
138  public static void main(String[] args) {
139  }
140
141  static boolean y;
142  static int live0;
143  static int live1;
144  static int live2;
145  static int live3;
146  static int live4;
147  static int live5;
148  static Foo foo;
149}
150