1 /*
2  * Copyright (c) 2020, Huawei Technologies Co. Ltd. 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 8243670
27  * @summary Unexpected test result caused by C2 MergeMemNode::Ideal
28  *
29  * @run main/othervm -Xcomp -XX:-SplitIfBlocks
30  *      -XX:CompileOnly=compiler.c2.TestReplaceEquivPhis::test
31  *      -XX:-BackgroundCompilation compiler.c2.TestReplaceEquivPhis
32  */
33 
34 package compiler.c2;
35 
36 public class TestReplaceEquivPhis {
37 
38     public static final int N = 400;
39     public static volatile int instanceCount = 0;
40     public int iFld = 0;
41     public static int iArrFld[] = new int[N];
42 
test()43     public int test() {
44         int v = 0;
45         boolean bArr[] = new boolean[N];
46 
47         for (int i = 1; i < 344; i++) {
48             iFld = i;
49             for (int j = 2; j <177 ; j++) {
50                 v = iFld;
51                 iFld = TestReplaceEquivPhis.instanceCount;
52                 TestReplaceEquivPhis.iArrFld[i] = 0;
53                 iFld += TestReplaceEquivPhis.instanceCount;
54                 TestReplaceEquivPhis.iArrFld[i] = 0;
55                 bArr[j] = false;
56                 TestReplaceEquivPhis.instanceCount = 1;
57 
58                 for (int k = 1; k < 3; k++) {
59                     // do nothing
60                 }
61             }
62         }
63         return v;
64     }
65 
main(String[] args)66     public static void main(String[] args) {
67             TestReplaceEquivPhis obj = new TestReplaceEquivPhis();
68             for (int i = 0; i < 5; i++) {
69                 int result = obj.test();
70                 if (result != 2) {
71                     throw new RuntimeException("Test failed.");
72                 }
73             }
74             System.out.println("Test passed.");
75     }
76 
77 }
78