|
1 /* |
|
2 * Copyright (c) 2019, 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 8230062 |
|
27 * @summary The IR of this test contains a reduction chain which corresponds to a pack in which the 2nd last element has a usage outside of the optimized loop. |
|
28 * |
|
29 * @run main/othervm -Xbatch -XX:CompileCommand=compileonly,compiler.loopopts.superword.SuperWordIntermediateUse::test |
|
30 * compiler.loopopts.superword.SuperWordIntermediateUse |
|
31 */ |
|
32 |
|
33 package compiler.loopopts.superword; |
|
34 |
|
35 public class SuperWordIntermediateUse { |
|
36 |
|
37 private int iFld; |
|
38 private int[] iArr = new int[1024]; |
|
39 |
|
40 public void test() { |
|
41 int local = 4; |
|
42 |
|
43 /** |
|
44 * Before unrolling this loop: |
|
45 * iFld: AddI 1 = -85 + Phi 1 |
|
46 * local: MulI 2 = Phi 1 * LoadI 3 |
|
47 * |
|
48 * This loop is now unrolled. 'local' is a reduction. The loop is first copied: |
|
49 * iFldCopy: AddI C1 = -85 + Phi C1 |
|
50 * localCopy: MulI C2 = Phi C1 * LoadI C3 |
|
51 * |
|
52 * iFld: AddI 1 = -85 + Phi 1 |
|
53 * local: MulI 2 = Phi 1 * LoadI 3 |
|
54 * |
|
55 * Then, the unnecessary nodes like phis are removed from the original loop by igvn: |
|
56 * (iFldCopy: AddI C1 = -85 + Phi C1) field store optimized away |
|
57 * localCopy: MulI C2 = Phi C1 * LoadI C3 |
|
58 * |
|
59 * iFld: AddI 1 = -85 + MulI C2 |
|
60 * local: MulI 2 = MulI C2 * LoadI 3 -> Input into Phi C1 |
|
61 * |
|
62 * As a result AddI 1 has an input from MulI C2 which isn't the last operation in the reduction chain |
|
63 * Phi C1 -> MulI C2 -> MulI 2 -> Phi C1 and therefore not the last element in a pack. |
|
64 * Additionally, AddI 1 does not belong to the loop being optimized: The store node for iFld is put outside of the loop being optimized. |
|
65 * This triggers the assertion bug when unrolled at least 4 times which creates packs of at least size 4. |
|
66 */ |
|
67 for (int i = 0; i < 1024; i++) { |
|
68 iFld = -85; |
|
69 iFld = iFld + local; |
|
70 local = local * iArr[i]; |
|
71 iArr[i] = 3; // Just used to trigger SuperWord optimization |
|
72 } |
|
73 } |
|
74 |
|
75 public static void main(String[] strArr) { |
|
76 SuperWordIntermediateUse instance = new SuperWordIntermediateUse(); |
|
77 for (int i = 0; i < 1000; i++) { |
|
78 instance.test(); |
|
79 } |
|
80 } |
|
81 } |