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 
17 public class Main {
18 
19   // CHECK-START: void Main.test1(boolean, int, int, int, int, int) register (after)
20   // CHECK:       name "B0"
21   // CHECK-NOT:     ParallelMove
22   // CHECK:       name "B1"
23   // CHECK-NOT:   end_block
24   // CHECK:         If
25   // CHECK-NOT:     ParallelMove
26   // CHECK:       name "B3"
27   // CHECK-NOT:   end_block
28   // CHECK:         ArraySet
29   // We could check here that there is a parallel move, but it's only valid
30   // for some architectures (for example x86), as other architectures may
31   // not do move at all.
32   // CHECK:       end_block
33   // CHECK-NOT:     ParallelMove
34 
test1(boolean z, int a, int b, int c, int d, int m)35   public static void test1(boolean z, int a, int b, int c, int d, int m) {
36     int e = live1;
37     int f = live2;
38     int g = live3;
39     if (z) {
40     } else {
41       // Create enough live instructions to force spilling on x86.
42       int h = live4;
43       int i = live5;
44       array[2] = e + i + h;
45       array[3] = f + i + h;
46       array[4] = g + i + h;
47       array[0] = h;
48       array[1] = i + h;
49 
50     }
51     live1 = e + f + g;
52   }
53 
54   // CHECK-START: void Main.test2(boolean, int, int, int, int, int) register (after)
55   // CHECK:       name "B0"
56   // CHECK-NOT:     ParallelMove
57   // CHECK:       name "B1"
58   // CHECK-NOT:   end_block
59   // CHECK:         If
60   // CHECK-NOT:     ParallelMove
61   // CHECK:       name "B3"
62   // CHECK-NOT:   end_block
63   // CHECK:         ArraySet
64   // We could check here that there is a parallel move, but it's only valid
65   // for some architectures (for example x86), as other architectures may
66   // not do move at all.
67   // CHECK:       end_block
68   // CHECK-NOT:     ParallelMove
69 
test2(boolean z, int a, int b, int c, int d, int m)70   public static void test2(boolean z, int a, int b, int c, int d, int m) {
71     int e = live1;
72     int f = live2;
73     int g = live3;
74     if (z) {
75       if (y) {
76         int h = live4;
77         int i = live5;
78         array[2] = e + i + h;
79         array[3] = f + i + h;
80         array[4] = g + i + h;
81         array[0] = h;
82         array[1] = i + h;
83       }
84     }
85     live1 = e + f + g;
86   }
87 
88   // CHECK-START: void Main.test3(boolean, int, int, int, int, int) register (after)
89   // CHECK:       name "B0"
90   // CHECK-NOT:     ParallelMove
91   // CHECK:       name "B1"
92   // CHECK-NOT:   end_block
93   // CHECK:         If
94   // CHECK-NOT:     ParallelMove
95   // CHECK:       name "B6"
96   // CHECK-NOT:   end_block
97   // CHECK:         ArraySet
98   // We could check here that there is a parallel move, but it's only valid
99   // for some architectures (for example x86), as other architectures may
100   // not do move at all.
101   // CHECK:       end_block
102   // CHECK-NOT:     ParallelMove
103 
test3(boolean z, int a, int b, int c, int d, int m)104   public static void test3(boolean z, int a, int b, int c, int d, int m) {
105     // Same version as test2, but with branches reversed, to ensure
106     // whatever linear order is computed, we will get the same results.
107     int e = live1;
108     int f = live2;
109     int g = live3;
110     if (z) {
111       live1 = e;
112     } else {
113       if (y) {
114         live1 = e;
115       } else {
116         int h = live4;
117         int i = live5;
118         array[2] = e + i + h;
119         array[3] = f + i + h;
120         array[4] = g + i + h;
121         array[0] = h;
122         array[1] = i + h;
123       }
124     }
125     live1 = e + f + g;
126   }
127 
main(String[] args)128   public static void main(String[] args) {
129   }
130 
131   static boolean y;
132   static int live1;
133   static int live2;
134   static int live3;
135   static int live4;
136   static int live5;
137   static int[] array;
138 }
139