test/hotspot/jtreg/compiler/loopopts/IterationSplitPredicateInconsistency.java
author roland
Thu, 22 Mar 2018 20:21:19 -0700
changeset 49487 bde392011cd8
child 50558 d9936e986e4f
permissions -rw-r--r--
8193130: Bad graph when unrolled loop bounds conflicts with range checks Reviewed-by: kvn, thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49487
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
     1
/*
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
     2
 * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
     4
 *
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
     8
 *
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    13
 * accompanied this code).
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    14
 *
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    18
 *
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    21
 * questions.
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    22
 */
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    23
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    24
/**
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    25
 * @test
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    26
 * @bug 8193130
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    27
 * @summary Bad graph when unrolled loop bounds conflicts with range checks
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    28
 *
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    29
 * @run main/othervm IterationSplitPredicateInconsistency
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    30
 * @run main/othervm -XX:-UseLoopPredicate IterationSplitPredicateInconsistency
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    31
 *
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    32
 */
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    33
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    34
public class IterationSplitPredicateInconsistency {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    35
    static volatile int barrier;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    36
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    37
    // Pollute profile so loop appears to run for a large number of iterations
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    38
    static boolean test1_helper(int start, int stop, double[] array1, double[] array2, int exit) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    39
        for (int i = start; i < stop; i++) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    40
            array1[i] = array2[i];
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    41
            if (i == exit) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    42
                return true;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    43
            }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    44
            barrier = 0x42;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    45
        }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    46
        return false;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    47
    }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    48
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    49
    static double[] test1(int start, double[] array2, int exit) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    50
        double[] array1 = new double[10];
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    51
        // Predication moves range checks out of loop and
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    52
        // pre/main/post loops are created. The main loop is unrolled
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    53
        // several times to the point where it's never executed but
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    54
        // compiler can't tell from the loop bounds alone. The lower
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    55
        // bound of the loop is negative and would cause range checks
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    56
        // (that were removed from the loop body) to fail.
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    57
        if (test1_helper(start, 5, array1, array2, exit)) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    58
            return null;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    59
        }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    60
        return array1;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    61
    }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    62
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    63
    // Same as above with other combinations of increasing/decreasing
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    64
    // loops, positive/negative stride
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    65
    static boolean test2_helper(int start, int stop, double[] array1, double[] array2, int exit) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    66
        for (int i = start-1; i >= stop; i--) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    67
            array1[i] = array2[i];
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    68
            if (i == exit) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    69
                return true;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    70
            }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    71
            barrier = 0x42;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    72
        }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    73
        return false;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    74
    }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    75
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    76
    static double[] test2(int start, double[] array2, int exit) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    77
        double[] array1 = new double[10];
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    78
        if (test2_helper(start, 0, array1, array2, exit)) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    79
            return null;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    80
        }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    81
        return array1;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    82
    }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    83
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    84
    static boolean test3_helper(int start, int stop, double[] array1, double[] array2, int exit) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    85
        for (int i = start; i < stop; i++) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    86
            array1[stop-i-1] = array2[stop-i-1];
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    87
            if (i == exit) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    88
                return true;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    89
            }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    90
            barrier = 0x42;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    91
        }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    92
        return false;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    93
    }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    94
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    95
    static double[] test3(int start, double[] array2, int exit) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    96
        double[] array1 = new double[5];
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    97
        if (test3_helper(start, 5, array1, array2, exit)) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    98
            return null;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
    99
        }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   100
        return array1;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   101
    }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   102
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   103
    static boolean test4_helper(int start, int stop, int from, double[] array1, double[] array2, int exit) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   104
        for (int i = start-1; i >= stop; i--) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   105
            array1[from-i-1] = array2[from-i-1];
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   106
            if (i == exit) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   107
                return true;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   108
            }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   109
            barrier = 0x42;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   110
        }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   111
        return false;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   112
    }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   113
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   114
    static double[] test4(int start, double[] array2, int exit) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   115
        double[] array1 = new double[5];
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   116
        if (test4_helper(start, 0, 5, array1, array2, exit)) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   117
            return null;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   118
        }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   119
        return array1;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   120
    }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   121
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   122
    public static void main(String[] args) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   123
        double[] array2 = new double[10];
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   124
        double[] array3 = new double[1000];
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   125
        for (int i = 0; i < 20_000; i++) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   126
            test1_helper(0, 1000, array3, array3, 998);
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   127
            test1(0, array2, 999);
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   128
            test1(0, array2, 4);
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   129
            test2_helper(1000, 0, array3, array3, 1);
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   130
            test2(5, array2, 999);
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   131
            test2(5, array2, 1);
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   132
            test3_helper(0, 1000, array3, array3, 998);
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   133
            test3(0, array2, 999);
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   134
            test3(0, array2, 4);
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   135
            test4_helper(1000, 0, 1000, array3, array3, 1);
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   136
            test4(5, array2, 999);
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   137
            test4(5, array2, 1);
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   138
        }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   139
    }
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents:
diff changeset
   140
}