Path: blob/master/test/hotspot/jtreg/compiler/loopopts/TestCountedLoopBadIVRange.java
41152 views
/*1* Copyright (c) 2017, Red Hat, Inc. 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*/2223/**24* @test25* @bug 819037526* @summary Bad range for IV phi when exit condition is a not equal test27* @run main/othervm -XX:-TieredCompilation TestCountedLoopBadIVRange28*29*/303132public class TestCountedLoopBadIVRange {3334static int test1(int[] arr) {35int j = 0;36int res = 0;37for (int i = 0; i < 2; i++) {38// When entered with j == 10, exit condition never39// succeeds so range of values for j can't be computed40// from exit condition41for (; j != 5; j++) {42if (j >= 20) {43break;44}45res += arr[j];46}47j = 10;48}49return res;50}5152static int test2(int[] arr) {53int j = 10;54int res = 0;55for (int i = 0; i < 2; i++) {56// Same as above but loop variable is decreasing57for (; j != 5; j--) {58if (j < 0) {59break;60}61res += arr[j];62}63j = 1;64}65return res;66}6768public static void main(String[] args) {69int[] arr = new int[20];70for (int i = 0; i < arr.length; i++) {71arr[i] = i;72}73for (int i = 0; i < 20_000; i++) {74int res = test1(arr);75if (res != 155) {76throw new RuntimeException("Incorrect result " + res);77}78res = test2(arr);79if (res != 41) {80throw new RuntimeException("Incorrect result " + res);81}82}83}84}858687