Path: blob/master/test/hotspot/jtreg/compiler/c2/Test5091921.java
41149 views
/*1* Copyright (c) 2011 Hewlett-Packard Company. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324/**25* @test26* @bug 509192127* @summary Sign flip issues in loop optimizer28*29* @run main/othervm -Xcomp -XX:+IgnoreUnrecognizedVMOptions -XX:MaxInlineSize=1 -XX:C1MaxInlineSize=130* -XX:CompileCommand=compileonly,compiler.c2.Test5091921::*31* compiler.c2.Test509192132*/3334package compiler.c2;3536public class Test5091921 {37private static int result = 0;383940/* Test for the bug of transforming indx >= MININT to indx > MININT-1 */41public static int test_ge1(int limit) {42int indx;43int sum = 0;44for (indx = 500; indx >= limit; indx -= 2) {45sum += 2000 / indx;46result = sum;47}48return sum;49}5051/* Test for the bug of transforming indx <= MAXINT to indx < MAXINT+1 */52public static int test_le1(int limit) {53int indx;54int sum = 0;55for (indx = -500; indx <= limit; indx += 2)56{57sum += 3000 / indx;58result = sum;59}60return sum;61}6263/* Run with -Xcomp -XX:CompileOnly=wrap1.test1 -XX:MaxInlineSize=1 */64/* limit reset to ((limit-init+stride-1)/stride)*stride+init */65/* Calculation may overflow */66public static volatile int c = 1;67public static int test_wrap1(int limit)68{69int indx;70int sum = 0;71for (indx = 0xffffffff; indx < limit; indx += 0x20000000)72{73sum += c;74}75return sum;76}7778/* Test for range check elimination with bit flip issue for79scale*i+offset<limit where offset is not 0 */80static int[] box5 = {1,2,3,4,5,6,7,8,9};81public static int test_rce5(int[] b, int limit)82{83int indx;84int sum = b[1];85result = sum;86for (indx = 0x80000000; indx < limit; ++indx)87{88if (indx > 0x80000000)89{90// this test is not issued in pre-loop but issued in main loop91// trick rce into thinking expression is false when indx >= 092// in fact it is false when indx==0x8000000193if (indx - 9 < -9)94{95sum += indx;96result = sum;97sum ^= b[indx & 7];98result = sum;99}100else101break;102}103else104{105sum += b[indx & 3];106result = sum;107}108}109return sum;110}111112/* Test for range check elimination with bit flip issue for113scale*i<limit where scale > 1 */114static int[] box6 = {1,2,3,4,5,6,7,8,9};115public static int test_rce6(int[] b, int limit)116{117int indx;118int sum = b[1];119result = sum;120for (indx = 0x80000000; indx < limit; ++indx)121{122if (indx > 0x80000000)123{124// harmless rce target125if (indx < 0)126{127sum += result;128result = sum;129}130else131break;132// this test is not issued in pre-loop but issued in main loop133// trick rce into thinking expression is false when indx >= 0134// in fact it is false when indx==0x80000001135// In compilers that transform mulI to shiftI may mask this issue.136if (indx * 28 + 1 < 0)137{138sum += indx;139result = sum;140sum ^= b[indx & 7];141result = sum;142}143else144break;145}146else147{148sum += b[indx & 3];149result = sum;150}151}152return sum;153}154155/* Test for range check elimination with i <= limit */156static int[] box7 = {1,2,3,4,5,6,7,8,9,0x7fffffff};157public static int test_rce7(int[] b)158{159int indx;160int max = b[9];161int sum = b[7];162result = sum;163for (indx = 0; indx < b.length; ++indx)164{165if (indx <= max)166{167sum += (indx ^ 15) + ((result != 0) ? 0 : sum);168result = sum;169}170else171throw new RuntimeException();172}173for (indx = -7; indx < b.length; ++indx)174{175if (indx <= 9)176{177sum += (sum ^ 15) + ((result != 0) ? 0 : sum);178result = sum;179}180else181throw new RuntimeException();182}183return sum;184}185186/* Test for range check elimination with i >= limit */187static int[] box8 = {-1,0,1,2,3,4,5,6,7,8,0x80000000};188public static int test_rce8(int[] b)189{190int indx;191int sum = b[5];192int min = b[10];193result = sum;194for (indx = b.length-1; indx >= 0; --indx)195{196if (indx >= min)197{198sum += (sum ^ 9) + ((result != 0) ? 0 :sum);199result = sum;200}201else202throw new RuntimeException();203}204return sum;205}206207public static void main(String[] args)208{209result=1;210int r = 0;211try {212r = test_ge1(0x80000000);213System.out.println(result);214System.out.println("test_ge1 FAILED");215System.exit(1);216}217catch (ArithmeticException e1) {218System.out.println("test_ge1: Expected exception caught");219if (result != 5986) {220System.out.println(result);221System.out.println("test_ge1 FAILED");222System.exit(97);223}224}225System.out.println("test_ge1 WORKED");226227result=0;228try229{230r = test_le1(0x7fffffff);231System.out.println(result);232System.out.println("test_le1 FAILED");233System.exit(1);234}235catch (ArithmeticException e1)236{237System.out.println("test_le1: Expected exception caught");238if (result != -9039)239{240System.out.println(result);241System.out.println("test_le1 FAILED");242System.exit(97);243}244}245System.out.println("test_le1 WORKED");246247result=0;248r = test_wrap1(0x7fffffff);249if (r != 4)250{251System.out.println(result);252System.out.println("test_wrap1 FAILED");253System.exit(97);254}255else256{257System.out.println("test_wrap1 WORKED");258}259260result=0;261r = test_rce5(box5,0x80000100);262if (result != 3)263{264System.out.println(result);265System.out.println("test_rce5 FAILED");266System.exit(97);267}268else269{270System.out.println("test_rce5 WORKED");271}272273result=0;274r = test_rce6(box6,0x80000100);275if (result != 6)276{277System.out.println(result);278System.out.println("test_rce6 FAILED");279System.exit(97);280}281else282{283System.out.println("test_rce6 WORKED");284}285286result=0;287r = test_rce7(box7);288if (result != 14680079)289{290System.out.println(result);291System.out.println("test_rce7 FAILED");292System.exit(97);293}294else295{296System.out.println("test_rce7 WORKED");297}298299result=0;300r = test_rce8(box8);301if (result != 16393)302{303System.out.println(result);304System.out.println("test_rce8 FAILED");305System.exit(97);306}307else308{309System.out.println("test_rce8 WORKED");310}311}312}313314315