1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
|
/*
* Copyright (c) 2011 Hewlett-Packard Company. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
/**
* @test
* @bug 5091921
* @summary Sign flip issues in loop optimizer
*
* @run main/othervm -Xcomp -XX:MaxInlineSize=1
* -XX:CompileCommand=compileonly,compiler.c2.Test5091921::*
* compiler.c2.Test5091921
*/
package compiler.c2;
public class Test5091921 {
private static int result = 0;
/* Test for the bug of transforming indx >= MININT to indx > MININT-1 */
public static int test_ge1(int limit) {
int indx;
int sum = 0;
for (indx = 500; indx >= limit; indx -= 2) {
sum += 2000 / indx;
result = sum;
}
return sum;
}
/* Test for the bug of transforming indx <= MAXINT to indx < MAXINT+1 */
public static int test_le1(int limit) {
int indx;
int sum = 0;
for (indx = -500; indx <= limit; indx += 2)
{
sum += 3000 / indx;
result = sum;
}
return sum;
}
/* Run with -Xcomp -XX:CompileOnly=wrap1.test1 -XX:MaxInlineSize=1 */
/* limit reset to ((limit-init+stride-1)/stride)*stride+init */
/* Calculation may overflow */
public static volatile int c = 1;
public static int test_wrap1(int limit)
{
int indx;
int sum = 0;
for (indx = 0xffffffff; indx < limit; indx += 0x20000000)
{
sum += c;
}
return sum;
}
/* Test for range check elimination with bit flip issue for
scale*i+offset<limit where offset is not 0 */
static int[] box5 = {1,2,3,4,5,6,7,8,9};
public static int test_rce5(int[] b, int limit)
{
int indx;
int sum = b[1];
result = sum;
for (indx = 0x80000000; indx < limit; ++indx)
{
if (indx > 0x80000000)
{
// this test is not issued in pre-loop but issued in main loop
// trick rce into thinking expression is false when indx >= 0
// in fact it is false when indx==0x80000001
if (indx - 9 < -9)
{
sum += indx;
result = sum;
sum ^= b[indx & 7];
result = sum;
}
else
break;
}
else
{
sum += b[indx & 3];
result = sum;
}
}
return sum;
}
/* Test for range check elimination with bit flip issue for
scale*i<limit where scale > 1 */
static int[] box6 = {1,2,3,4,5,6,7,8,9};
public static int test_rce6(int[] b, int limit)
{
int indx;
int sum = b[1];
result = sum;
for (indx = 0x80000000; indx < limit; ++indx)
{
if (indx > 0x80000000)
{
// harmless rce target
if (indx < 0)
{
sum += result;
result = sum;
}
else
break;
// this test is not issued in pre-loop but issued in main loop
// trick rce into thinking expression is false when indx >= 0
// in fact it is false when indx==0x80000001
// In compilers that transform mulI to shiftI may mask this issue.
if (indx * 28 + 1 < 0)
{
sum += indx;
result = sum;
sum ^= b[indx & 7];
result = sum;
}
else
break;
}
else
{
sum += b[indx & 3];
result = sum;
}
}
return sum;
}
/* Test for range check elimination with i <= limit */
static int[] box7 = {1,2,3,4,5,6,7,8,9,0x7fffffff};
public static int test_rce7(int[] b)
{
int indx;
int max = b[9];
int sum = b[7];
result = sum;
for (indx = 0; indx < b.length; ++indx)
{
if (indx <= max)
{
sum += (indx ^ 15) + ((result != 0) ? 0 : sum);
result = sum;
}
else
throw new RuntimeException();
}
for (indx = -7; indx < b.length; ++indx)
{
if (indx <= 9)
{
sum += (sum ^ 15) + ((result != 0) ? 0 : sum);
result = sum;
}
else
throw new RuntimeException();
}
return sum;
}
/* Test for range check elimination with i >= limit */
static int[] box8 = {-1,0,1,2,3,4,5,6,7,8,0x80000000};
public static int test_rce8(int[] b)
{
int indx;
int sum = b[5];
int min = b[10];
result = sum;
for (indx = b.length-1; indx >= 0; --indx)
{
if (indx >= min)
{
sum += (sum ^ 9) + ((result != 0) ? 0 :sum);
result = sum;
}
else
throw new RuntimeException();
}
return sum;
}
public static void main(String[] args)
{
result=1;
int r = 0;
try {
r = test_ge1(0x80000000);
System.out.println(result);
System.out.println("test_ge1 FAILED");
System.exit(1);
}
catch (ArithmeticException e1) {
System.out.println("test_ge1: Expected exception caught");
if (result != 5986) {
System.out.println(result);
System.out.println("test_ge1 FAILED");
System.exit(97);
}
}
System.out.println("test_ge1 WORKED");
result=0;
try
{
r = test_le1(0x7fffffff);
System.out.println(result);
System.out.println("test_le1 FAILED");
System.exit(1);
}
catch (ArithmeticException e1)
{
System.out.println("test_le1: Expected exception caught");
if (result != -9039)
{
System.out.println(result);
System.out.println("test_le1 FAILED");
System.exit(97);
}
}
System.out.println("test_le1 WORKED");
result=0;
r = test_wrap1(0x7fffffff);
if (r != 4)
{
System.out.println(result);
System.out.println("test_wrap1 FAILED");
System.exit(97);
}
else
{
System.out.println("test_wrap1 WORKED");
}
result=0;
r = test_rce5(box5,0x80000100);
if (result != 3)
{
System.out.println(result);
System.out.println("test_rce5 FAILED");
System.exit(97);
}
else
{
System.out.println("test_rce5 WORKED");
}
result=0;
r = test_rce6(box6,0x80000100);
if (result != 6)
{
System.out.println(result);
System.out.println("test_rce6 FAILED");
System.exit(97);
}
else
{
System.out.println("test_rce6 WORKED");
}
result=0;
r = test_rce7(box7);
if (result != 14680079)
{
System.out.println(result);
System.out.println("test_rce7 FAILED");
System.exit(97);
}
else
{
System.out.println("test_rce7 WORKED");
}
result=0;
r = test_rce8(box8);
if (result != 16393)
{
System.out.println(result);
System.out.println("test_rce8 FAILED");
System.exit(97);
}
else
{
System.out.println("test_rce8 WORKED");
}
}
}
|