1 /*
2  * Copyright (c) 2020, 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 8249607
27  * @summary A LoadNode is pinned in split_if_with_blocks_post() on a loop exit node x that is part of a strip mined loop. It has a late control y outside
28             the outer strip mined loop. After pre-main-post, the dominator chain of y does not include x anymore resulting in an assertion failure.
29  * @run main/othervm -Xbatch -XX:CompileCommand=compileonly,compiler.loopopts.TestSplitIfPinnedLoadInStripMinedLoop::*
30  *                   compiler.loopopts.TestSplitIfPinnedLoadInStripMinedLoop
31  */
32 package compiler.loopopts;
33 
34 public class TestSplitIfPinnedLoadInStripMinedLoop {
35 
36     public boolean bFld = false;
37     public short sFld = 4;
38     public static int iFld = 5;
39     public static float fFld= 6.0f;
40     public static int iArrFld[] = new int[400];
41 
test()42     public void test() {
43         int x = 7;
44         int y = 8;
45         int a = 9;
46         float f = 10.0f;
47         double d = 11.0f;
48         double dArr[] = new double[400];
49 
50         for (int i = 16; i < 350; i++) {
51             for (int j = 1; j < 75; j++) {
52                 for (int k = 1; k < 3; k++) {
53                 }
54                 f = j * 6;
55                 y = j;
56                 try {
57                     x = (y / 148);
58                 } catch (ArithmeticException a_e) {}
59                 if (bFld) {
60                     break;
61                 }
62                 dArr[1] = 4;
63             }
64             for (int k = 75; k > i; k--) {
65                 iArrFld[k] = 5;
66             }
67             for (int k = 4; k < 75; k++) {
68                 f -= fFld;
69                 // The LoadSNode for sFld is cloned in split_if_with_blocks_post() for each use such that they can float out of the loop. All control
70                 // inputs of the clone are set to the latest control of the original LoadSNode which in this case is the StoreSNode for iFld that is
71                 // aninput to a MergeMemNode which is an input to the SafePointNode in the outer strip mined loop. Both these nodes are not part
72                 // of the loop body and thus the StoreNode is also not part of the loop anymore. This means that all the new LoadNode clones get
73                 // the loop exit l inside the outer strip mined loop as control input. Some of these clones (**) have a late control outside of
74                 // this outer strip mined loop. The dominator chain from the controls nodes of (**) contain l. However, after pre-main-post, we
75                 // insert additional Region nodes but do not account for these control inputs of the LoadSNodes. They remain unchanged and still
76                 // have l as control input. As a consequence, we do not find l on the dominator chains from the control nodes of (**) anymore
77                 // resulting in a dominator assertion failure.
78                 iFld = sFld;
79             }
80             switch ((i % 8) + 27) {
81             case 27:
82                 if (bFld) {
83                     for (a = 1; a < 75; a++) {
84                         iFld += 6; // (**)
85                     }
86                 } else {
87                     d -= x;
88                 }
89                 break;
90             case 28:
91                 iFld = y;
92                 // Fall through
93             case 33:
94             case 34:
95                 iFld -= (int)d; // (**)
96                 break;
97             }
98         }
99     }
main(String[] strArr)100     public static void main(String[] strArr) {
101         TestSplitIfPinnedLoadInStripMinedLoop t = new TestSplitIfPinnedLoadInStripMinedLoop();
102         for (int i = 0; i < 10; i++) {
103             t.test();
104         }
105     }
106 }
107