GVNTest.java revision 11707:ad7af1afda7a
1132451Sroberto/* 2132451Sroberto * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3132451Sroberto * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4132451Sroberto * 5132451Sroberto * This code is free software; you can redistribute it and/or modify it 6132451Sroberto * under the terms of the GNU General Public License version 2 only, as 7182007Sroberto * published by the Free Software Foundation. 8132451Sroberto * 9132451Sroberto * This code is distributed in the hope that it will be useful, but WITHOUT 10132451Sroberto * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11132451Sroberto * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12132451Sroberto * version 2 for more details (a copy is included in the LICENSE file that 13132451Sroberto * accompanied this code). 14132451Sroberto * 15132451Sroberto * You should have received a copy of the GNU General Public License version 16132451Sroberto * 2 along with this work; if not, write to the Free Software Foundation, 17132451Sroberto * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18132451Sroberto * 19132451Sroberto * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20132451Sroberto * or visit www.oracle.com if you need additional information or have any 21132451Sroberto * questions. 22132451Sroberto */ 23132451Sroberto 24132451Sroberto/* 25132451Sroberto * @test 26132451Sroberto * @bug 8028207 27132451Sroberto * @summary Verify that GVN doesn't mess up the two addExacts 28132451Sroberto * 29132451Sroberto * @run main compiler.intrinsics.mathexact.GVNTest 30132451Sroberto */ 31132451Sroberto 32132451Srobertopackage compiler.intrinsics.mathexact; 33132451Sroberto 34132451Srobertopublic class GVNTest { 35132451Sroberto public static int result = 0; 36132451Sroberto public static int value = 93; 37132451Sroberto public static void main(String[] args) { 38132451Sroberto for (int i = 0; i < 50000; ++i) { 39132451Sroberto result = runTest(value + i); 40132451Sroberto result = runTest(value + i); 41132451Sroberto result = runTest(value + i); 42132451Sroberto result = runTest(value + i); 43132451Sroberto result = runTest(value + i); 44132451Sroberto } 45132451Sroberto } 46132451Sroberto 47132451Sroberto public static int runTest(int value) { 48132451Sroberto int v = value + value; 49132451Sroberto int sum = 0; 50132451Sroberto if (v < 4032) { 51132451Sroberto for (int i = 0; i < 1023; ++i) { 52132451Sroberto sum += Math.addExact(value, value); 53132451Sroberto } 54132451Sroberto } else { 55132451Sroberto for (int i = 0; i < 321; ++i) { 56132451Sroberto sum += Math.addExact(value, value); 57132451Sroberto } 58132451Sroberto } 59132451Sroberto return sum + v; 60132451Sroberto } 61132451Sroberto} 62132451Sroberto