10011
|
1 |
/*
|
|
2 |
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/**
|
|
25 |
* @test
|
|
26 |
* @bug 7044738
|
|
27 |
* @summary Loop unroll optimization causes incorrect result
|
|
28 |
*
|
40059
|
29 |
* @run main/othervm -Xbatch compiler.loopopts.Test7044738
|
10011
|
30 |
*/
|
|
31 |
|
40059
|
32 |
package compiler.loopopts;
|
|
33 |
|
10011
|
34 |
public class Test7044738 {
|
|
35 |
|
40059
|
36 |
private static final int INITSIZE = 10000;
|
|
37 |
public int d[] = {1, 2, 3, 4};
|
|
38 |
public int i, size;
|
10011
|
39 |
|
40059
|
40 |
private static int iter = 5;
|
10011
|
41 |
|
40059
|
42 |
boolean done() {
|
|
43 |
return (--iter > 0);
|
|
44 |
}
|
10011
|
45 |
|
40059
|
46 |
public static void main(String args[]) {
|
|
47 |
Test7044738 t = new Test7044738();
|
|
48 |
t.test();
|
|
49 |
}
|
10011
|
50 |
|
40059
|
51 |
int test() {
|
10011
|
52 |
|
40059
|
53 |
while (done()) {
|
|
54 |
size = INITSIZE;
|
10011
|
55 |
|
40059
|
56 |
for (i = 0; i < size; i++) {
|
|
57 |
d[0] = d[1]; // 2
|
|
58 |
d[1] = d[2]; // 3
|
|
59 |
d[2] = d[3]; // 4
|
|
60 |
d[3] = d[0]; // 2
|
10011
|
61 |
|
40059
|
62 |
d[0] = d[1]; // 3
|
|
63 |
d[1] = d[2]; // 4
|
|
64 |
d[2] = d[3]; // 2
|
|
65 |
d[3] = d[0]; // 3
|
10011
|
66 |
|
40059
|
67 |
d[0] = d[1]; // 4
|
|
68 |
d[1] = d[2]; // 2
|
|
69 |
d[2] = d[3]; // 3
|
|
70 |
d[3] = d[0]; // 4
|
10011
|
71 |
|
40059
|
72 |
d[0] = d[1]; // 2
|
|
73 |
d[1] = d[2]; // 3
|
|
74 |
d[2] = d[3]; // 4
|
|
75 |
d[3] = d[0]; // 2
|
10011
|
76 |
|
40059
|
77 |
d[0] = d[1]; // 3
|
|
78 |
d[1] = d[2]; // 4
|
|
79 |
d[2] = d[3]; // 2
|
|
80 |
d[3] = d[0]; // 3
|
10011
|
81 |
|
40059
|
82 |
d[0] = d[1]; // 4
|
|
83 |
d[1] = d[2]; // 2
|
|
84 |
d[2] = d[3]; // 3
|
|
85 |
d[3] = d[0]; // 4
|
10011
|
86 |
|
40059
|
87 |
d[0] = d[1]; // 2
|
|
88 |
d[1] = d[2]; // 3
|
|
89 |
d[2] = d[3]; // 4
|
|
90 |
d[3] = d[0]; // 2
|
10011
|
91 |
|
40059
|
92 |
d[0] = d[1]; // 3
|
|
93 |
d[1] = d[2]; // 4
|
|
94 |
d[2] = d[3]; // 2
|
|
95 |
d[3] = d[0]; // 3
|
|
96 |
}
|
|
97 |
|
|
98 |
// try to defeat dead code elimination
|
|
99 |
if (d[0] == d[1]) {
|
|
100 |
System.out.println("test failed: iter=" + iter + " i=" + i + " d[] = { " + d[0] + ", " + d[1] + ", " + d[2] + ", " + d[3] + " } ");
|
|
101 |
System.exit(97);
|
|
102 |
}
|
|
103 |
}
|
|
104 |
return d[3];
|
10011
|
105 |
}
|
|
106 |
}
|