hotspot/test/compiler/loopopts/TestLoopPeeling.java
author chegar
Tue, 22 Mar 2016 15:26:07 +0000
changeset 36694 182a5e7a519e
parent 35574 2b25eb88c8d6
child 40059 c2304140ed64
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35574
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
     1
/*
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
     4
 *
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
     8
 *
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    13
 * accompanied this code).
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    14
 *
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    18
 *
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    21
 * questions.
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    22
 */
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    23
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    24
/*
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    25
 * @test
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    26
 * @bug 8078262
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    27
 * @summary Tests correct dominator information after loop peeling.
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    28
 * @run main/othervm -Xcomp -XX:CompileCommand=compileonly,TestLoopPeeling::test* TestLoopPeeling
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    29
 */
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    30
public class TestLoopPeeling {
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    31
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    32
    public int[] array = new int[100];
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    33
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    34
    public static void main(String args[]) {
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    35
        TestLoopPeeling test = new TestLoopPeeling();
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    36
        try {
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    37
            test.testArrayAccess(0, 1);
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    38
            test.testArrayAllocation(0, 1);
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    39
        } catch (Exception e) {
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    40
            // Ignore exceptions
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    41
        }
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    42
    }
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    43
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    44
    public void testArrayAccess(int index, int inc) {
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    45
        int storeIndex = -1;
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    46
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    47
        for (; index < 10; index += inc) {
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    48
            // This loop invariant check triggers loop peeling because it can
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    49
            // be moved out of the loop (see 'IdealLoopTree::policy_peeling').
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    50
            if (inc == 42) return;
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    51
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    52
            // This loop variant usage of LShiftL( ConvI2L( Phi(storeIndex) ) )
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    53
            // prevents the split if optimization that would otherwise clone the
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    54
            // LShiftL and ConvI2L nodes and assign them to their corresponding array
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    55
            // address computation (see 'PhaseIdealLoop::split_if_with_blocks_post').
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    56
            if (storeIndex > 0 && array[storeIndex] == 42) return;
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    57
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    58
            if (index == 42) {
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    59
                // This store and the corresponding range check are moved out of the
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    60
                // loop and both used after old loop and the peeled iteration exit.
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    61
                // For the peeled iteration, storeIndex is always -1 and the ConvI2L
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    62
                // is replaced by TOP. However, the range check is not folded because
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    63
                // we don't do the split if optimization in PhaseIdealLoop2.
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    64
                // As a result, we have a (dead) control path from the peeled iteration
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    65
                // to the StoreI but the data path is removed.
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    66
                array[storeIndex] = 1;
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    67
                return;
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    68
            }
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    69
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    70
            storeIndex++;
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    71
        }
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    72
    }
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    73
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    74
    public byte[] testArrayAllocation(int index, int inc) {
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    75
        int allocationCount = -1;
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    76
        byte[] result;
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    77
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    78
        for (; index < 10; index += inc) {
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    79
            // This loop invariant check triggers loop peeling because it can
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    80
            // be moved out of the loop (see 'IdealLoopTree::policy_peeling').
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    81
            if (inc == 42) return null;
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    82
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    83
            if (index == 42) {
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    84
                // This allocation and the corresponding size check are moved out of the
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    85
                // loop and both used after old loop and the peeled iteration exit.
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    86
                // For the peeled iteration, allocationCount is always -1 and the ConvI2L
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    87
                // is replaced by TOP. However, the size check is not folded because
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    88
                // we don't do the split if optimization in PhaseIdealLoop2.
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    89
                // As a result, we have a (dead) control path from the peeled iteration
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    90
                // to the allocation but the data path is removed.
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    91
                result = new byte[allocationCount];
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    92
                return result;
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    93
            }
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    94
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    95
            allocationCount++;
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    96
        }
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    97
        return null;
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    98
    }
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
    99
}
2b25eb88c8d6 6675699: need comprehensive fix for unconstrained ConvI2L with narrowed type
thartmann
parents:
diff changeset
   100