Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/compiler/5091921/Test5091921.java
32285 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:CompileOnly=Test5091921 -XX:MaxInlineSize=1 Test509192130*/3132public class Test5091921 {33private static int result = 0;343536/* Test for the bug of transforming indx >= MININT to indx > MININT-1 */37public static int test_ge1(int limit) {38int indx;39int sum = 0;40for (indx = 500; indx >= limit; indx -= 2) {41sum += 2000 / indx;42result = sum;43}44return sum;45}4647/* Test for the bug of transforming indx <= MAXINT to indx < MAXINT+1 */48public static int test_le1(int limit) {49int indx;50int sum = 0;51for (indx = -500; indx <= limit; indx += 2)52{53sum += 3000 / indx;54result = sum;55}56return sum;57}5859/* Run with -Xcomp -XX:CompileOnly=wrap1.test1 -XX:MaxInlineSize=1 */60/* limit reset to ((limit-init+stride-1)/stride)*stride+init */61/* Calculation may overflow */62public static volatile int c = 1;63public static int test_wrap1(int limit)64{65int indx;66int sum = 0;67for (indx = 0xffffffff; indx < limit; indx += 0x20000000)68{69sum += c;70}71return sum;72}7374/* Test for range check elimination with bit flip issue for75scale*i+offset<limit where offset is not 0 */76static int[] box5 = {1,2,3,4,5,6,7,8,9};77public static int test_rce5(int[] b, int limit)78{79int indx;80int sum = b[1];81result = sum;82for (indx = 0x80000000; indx < limit; ++indx)83{84if (indx > 0x80000000)85{86// this test is not issued in pre-loop but issued in main loop87// trick rce into thinking expression is false when indx >= 088// in fact it is false when indx==0x8000000189if (indx - 9 < -9)90{91sum += indx;92result = sum;93sum ^= b[indx & 7];94result = sum;95}96else97break;98}99else100{101sum += b[indx & 3];102result = sum;103}104}105return sum;106}107108/* Test for range check elimination with bit flip issue for109scale*i<limit where scale > 1 */110static int[] box6 = {1,2,3,4,5,6,7,8,9};111public static int test_rce6(int[] b, int limit)112{113int indx;114int sum = b[1];115result = sum;116for (indx = 0x80000000; indx < limit; ++indx)117{118if (indx > 0x80000000)119{120// harmless rce target121if (indx < 0)122{123sum += result;124result = sum;125}126else127break;128// this test is not issued in pre-loop but issued in main loop129// trick rce into thinking expression is false when indx >= 0130// in fact it is false when indx==0x80000001131// In compilers that transform mulI to shiftI may mask this issue.132if (indx * 28 + 1 < 0)133{134sum += indx;135result = sum;136sum ^= b[indx & 7];137result = sum;138}139else140break;141}142else143{144sum += b[indx & 3];145result = sum;146}147}148return sum;149}150151/* Test for range check elimination with i <= limit */152static int[] box7 = {1,2,3,4,5,6,7,8,9,0x7fffffff};153public static int test_rce7(int[] b)154{155int indx;156int max = b[9];157int sum = b[7];158result = sum;159for (indx = 0; indx < b.length; ++indx)160{161if (indx <= max)162{163sum += (indx ^ 15) + ((result != 0) ? 0 : sum);164result = sum;165}166else167throw new RuntimeException();168}169for (indx = -7; indx < b.length; ++indx)170{171if (indx <= 9)172{173sum += (sum ^ 15) + ((result != 0) ? 0 : sum);174result = sum;175}176else177throw new RuntimeException();178}179return sum;180}181182/* Test for range check elimination with i >= limit */183static int[] box8 = {-1,0,1,2,3,4,5,6,7,8,0x80000000};184public static int test_rce8(int[] b)185{186int indx;187int sum = b[5];188int min = b[10];189result = sum;190for (indx = b.length-1; indx >= 0; --indx)191{192if (indx >= min)193{194sum += (sum ^ 9) + ((result != 0) ? 0 :sum);195result = sum;196}197else198throw new RuntimeException();199}200return sum;201}202203public static void main(String[] args)204{205result=1;206int r = 0;207try {208r = test_ge1(0x80000000);209System.out.println(result);210System.out.println("test_ge1 FAILED");211System.exit(1);212}213catch (ArithmeticException e1) {214System.out.println("test_ge1: Expected exception caught");215if (result != 5986) {216System.out.println(result);217System.out.println("test_ge1 FAILED");218System.exit(97);219}220}221System.out.println("test_ge1 WORKED");222223result=0;224try225{226r = test_le1(0x7fffffff);227System.out.println(result);228System.out.println("test_le1 FAILED");229System.exit(1);230}231catch (ArithmeticException e1)232{233System.out.println("test_le1: Expected exception caught");234if (result != -9039)235{236System.out.println(result);237System.out.println("test_le1 FAILED");238System.exit(97);239}240}241System.out.println("test_le1 WORKED");242243result=0;244r = test_wrap1(0x7fffffff);245if (r != 4)246{247System.out.println(result);248System.out.println("test_wrap1 FAILED");249System.exit(97);250}251else252{253System.out.println("test_wrap1 WORKED");254}255256result=0;257r = test_rce5(box5,0x80000100);258if (result != 3)259{260System.out.println(result);261System.out.println("test_rce5 FAILED");262System.exit(97);263}264else265{266System.out.println("test_rce5 WORKED");267}268269result=0;270r = test_rce6(box6,0x80000100);271if (result != 6)272{273System.out.println(result);274System.out.println("test_rce6 FAILED");275System.exit(97);276}277else278{279System.out.println("test_rce6 WORKED");280}281282result=0;283r = test_rce7(box7);284if (result != 14680079)285{286System.out.println(result);287System.out.println("test_rce7 FAILED");288System.exit(97);289}290else291{292System.out.println("test_rce7 WORKED");293}294295result=0;296r = test_rce8(box8);297if (result != 16393)298{299System.out.println(result);300System.out.println("test_rce8 FAILED");301System.exit(97);302}303else304{305System.out.println("test_rce8 WORKED");306}307}308}309310311