test/hotspot/jtreg/compiler/loopopts/superword/SuperWordIntermediateUse.java
author chagedorn
Wed, 23 Oct 2019 12:17:14 +0200
changeset 58750 c8d42aa9359a
permissions -rw-r--r--
8232874: Add missing test for 8230062 Summary: Adds a missing test which verifies the bug fix of 8230062. Reviewed-by: roland, thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58750
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
     1
/*
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
     4
 *
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
     8
 *
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    13
 * accompanied this code).
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    14
 *
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    18
 *
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    21
 * questions.
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    22
 */
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    23
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    24
/**
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    25
 * @test
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    26
 * @bug 8230062
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    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.
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    28
 *
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    29
 * @run main/othervm -Xbatch -XX:CompileCommand=compileonly,compiler.loopopts.superword.SuperWordIntermediateUse::test
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    30
 *      compiler.loopopts.superword.SuperWordIntermediateUse
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    31
 */
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    32
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    33
package compiler.loopopts.superword;
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    34
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    35
public class SuperWordIntermediateUse {
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    36
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    37
    private int iFld;
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    38
    private int[] iArr = new int[1024];
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    39
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    40
    public void test() {
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    41
        int local = 4;
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    42
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    43
        /**
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    44
         * Before unrolling this loop:
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    45
         * iFld:   AddI 1 = -85 + Phi 1
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    46
         * local:  MulI 2 = Phi 1 * LoadI 3
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    47
         *
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    48
         * This loop is now unrolled. 'local' is a reduction. The loop is first copied:
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    49
         * iFldCopy:  AddI C1 = -85 + Phi C1
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    50
         * localCopy: MulI C2 = Phi C1 * LoadI C3
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    51
         *
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    52
         * iFld:   AddI 1 = -85 + Phi 1
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    53
         * local:  MulI 2 = Phi 1 * LoadI 3
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    54
         *
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    55
         * Then, the unnecessary nodes like phis are removed from the original loop by igvn:
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    56
         * (iFldCopy:  AddI C1 = -85 + Phi C1) field store optimized away
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    57
         * localCopy: MulI C2 = Phi C1 * LoadI C3
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    58
         *
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    59
         * iFld:   AddI 1 = -85 + MulI C2
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    60
         * local:  MulI 2 = MulI C2 * LoadI 3 -> Input into Phi C1
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    61
         *
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    62
         *  As a result AddI 1 has an input from MulI C2 which isn't the last operation in the reduction chain
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    63
         *  Phi C1 -> MulI C2 -> MulI 2 -> Phi C1 and therefore not the last element in a pack.
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    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.
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    65
         *  This triggers the assertion bug when unrolled at least 4 times which creates packs of at least size 4.
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    66
         */
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    67
        for (int i = 0; i < 1024; i++) {
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    68
            iFld = -85;
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    69
            iFld = iFld + local;
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    70
            local = local * iArr[i];
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    71
            iArr[i] = 3; // Just used to trigger SuperWord optimization
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    72
        }
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    73
    }
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    74
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    75
    public static void main(String[] strArr) {
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    76
        SuperWordIntermediateUse instance = new SuperWordIntermediateUse();
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    77
        for (int i = 0; i < 1000; i++) {
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    78
            instance.test();
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    79
        }
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    80
    }
c8d42aa9359a 8232874: Add missing test for 8230062
chagedorn
parents:
diff changeset
    81
}