|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, 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 8262017 |
| 27 | + * @summary Dominator failure because ConvL2I node becomes TOP due to missing overflow/underflow handling in range check elimination |
| 28 | + * in PhaseIdealLoop::add_constraint(). |
| 29 | + * @run main/othervm -Xcomp -XX:-TieredCompilation -XX:CompileCommand=compileonly,compiler.rangechecks.TestRangeCheckLimits::* |
| 30 | + * compiler.rangechecks.TestRangeCheckLimits |
| 31 | + */ |
| 32 | + |
| 33 | + package compiler.rangechecks; |
| 34 | + |
| 35 | + public class TestRangeCheckLimits { |
| 36 | + static int a = 400; |
| 37 | + static volatile int b; |
| 38 | + static long lFld; |
| 39 | + static int iFld; |
| 40 | + |
| 41 | + public static void main(String[] k) { |
| 42 | + // Test all cases in PhaseIdealLoop::add_constraint(). |
| 43 | + testPositiveCaseMainLoop(); |
| 44 | + testNegativeCaseMainLoop(); |
| 45 | + testPositiveCasePreLoop(); |
| 46 | + testNegativeCasePreLoop(); |
| 47 | + } |
| 48 | + |
| 49 | + public static void testPositiveCaseMainLoop() { |
| 50 | + int e, f, g = 0, h[] = new int[a]; |
| 51 | + double i[] = new double[a]; |
| 52 | + long j = 9; |
| 53 | + Helper.init(h, 3); |
| 54 | + for (e = 5; e < 154; e++) { |
| 55 | + for (f = 1; f < 169; f += 2) { |
| 56 | + b = e; |
| 57 | + } |
| 58 | + i[1] = b; |
| 59 | + for (g = 8; g < 168; g += 2) { |
| 60 | + j = g - 5; |
| 61 | + if (j > Integer.MAX_VALUE - 1) { |
| 62 | + switch (3) { |
| 63 | + case 3: |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + if (g != 168) { |
| 69 | + throw new RuntimeException("fail"); |
| 70 | + } |
| 71 | + lFld = j; |
| 72 | + } |
| 73 | + |
| 74 | + |
| 75 | + public static void testPositiveCasePreLoop() { |
| 76 | + int e, f, g = 0, h[] = new int[a]; |
| 77 | + double i[] = new double[a]; |
| 78 | + long j = 9; |
| 79 | + Helper.init(h, 3); |
| 80 | + for (e = 5; e < 154; e++) { |
| 81 | + for (f = 1; f < 169; f += 2) { |
| 82 | + b = e; |
| 83 | + } |
| 84 | + i[1] = b; |
| 85 | + for (g = 8; g < 168; g += 2) { |
| 86 | + j = g + 5; |
| 87 | + if (j > 180) { |
| 88 | + switch (3) { |
| 89 | + case 3: |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + if (g != 168) { |
| 95 | + throw new RuntimeException("fail"); |
| 96 | + } |
| 97 | + lFld = j; |
| 98 | + } |
| 99 | + |
| 100 | + public static void testNegativeCaseMainLoop() { |
| 101 | + int e, f, g = 0, h[] = new int[a]; |
| 102 | + double i[] = new double[a]; |
| 103 | + long j = 9; |
| 104 | + Helper.init(h, 3); |
| 105 | + for (e = 5; e < 154; e++) { |
| 106 | + for (f = 1; f < 169; f += 2) { |
| 107 | + b = e; |
| 108 | + } |
| 109 | + i[1] = b; |
| 110 | + for (g = 8; g < 168; g += 2) { |
| 111 | + j = g; |
| 112 | + if (j < 5) { |
| 113 | + switch (3) { |
| 114 | + case 3: |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + if (g != 168) { |
| 120 | + throw new RuntimeException("fail"); |
| 121 | + } |
| 122 | + lFld = j; |
| 123 | + } |
| 124 | + |
| 125 | + |
| 126 | + public static void testNegativeCasePreLoop() { |
| 127 | + int e, f, g = 0, h[] = new int[a]; |
| 128 | + double i[] = new double[a]; |
| 129 | + long j = 9; |
| 130 | + Helper.init(h, 3); |
| 131 | + for (e = 5; e < 154; e++) { |
| 132 | + for (f = 1; f < 169; f += 2) { |
| 133 | + b = e; |
| 134 | + } |
| 135 | + i[1] = b; |
| 136 | + for (g = 168; g > 8; g -= 2) { |
| 137 | + j = g - 5; |
| 138 | + if (j > Integer.MAX_VALUE - 1) { |
| 139 | + switch (3) { |
| 140 | + case 3: |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | + if (g != 8) { |
| 146 | + throw new RuntimeException("fail"); |
| 147 | + } |
| 148 | + lFld = j; |
| 149 | + } |
| 150 | +} |
| 151 | + |
| 152 | +class Helper { |
| 153 | + public static void init(int[] a, int seed) { |
| 154 | + for (int j = 0; j < a.length; j++) { |
| 155 | + a[j] = (j % 2 == 0) ? seed + j : seed - j; |
| 156 | + } |
| 157 | + } |
| 158 | +} |
0 commit comments