/*
* Copyright (c) 2011 Hewlett-Packard Company. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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
*
*/
public class Test5091921 {
/* Test for the bug of transforming indx >= MININT to indx > MININT-1 */
int indx;
int sum = 0;
}
return sum;
}
/* Test for the bug of transforming indx <= MAXINT to indx < MAXINT+1 */
int indx;
int sum = 0;
{
}
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;
{
int indx;
int sum = 0;
{
sum += c;
}
return sum;
}
/* Test for range check elimination with bit flip issue for
scale*i+offset<limit where offset is not 0 */
{
int indx;
int sum = b[1];
{
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
{
}
else
break;
}
else
{
}
}
return sum;
}
/* Test for range check elimination with bit flip issue for
scale*i<limit where scale > 1 */
{
int indx;
int sum = b[1];
{
if (indx > 0x80000000)
{
// harmless rce target
if (indx < 0)
{
}
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.
{
}
else
break;
}
else
{
}
}
return sum;
}
/* Test for range check elimination with i <= limit */
public static int test_rce7(int[] b)
{
int indx;
int max = b[9];
int sum = b[7];
{
{
}
else
throw new RuntimeException();
}
{
if (indx <= 9)
{
}
else
throw new RuntimeException();
}
return sum;
}
/* Test for range check elimination with i >= limit */
public static int test_rce8(int[] b)
{
int indx;
int sum = b[5];
int min = b[10];
{
{
}
else
throw new RuntimeException();
}
return sum;
}
{
result=1;
int r = 0;
try {
r = test_ge1(0x80000000);
}
catch (ArithmeticException e1) {
if (result != 5986) {
}
}
result=0;
try
{
r = test_le1(0x7fffffff);
}
catch (ArithmeticException e1)
{
if (result != -9039)
{
}
}
result=0;
r = test_wrap1(0x7fffffff);
if (r != 4)
{
}
else
{
}
result=0;
if (result != 3)
{
}
else
{
}
result=0;
if (result != 6)
{
}
else
{
}
result=0;
if (result != 14680079)
{
}
else
{
}
result=0;
if (result != 16393)
{
}
else
{
}
}
}