hotspot/test/compiler/5091921/Test5091921.java
author pchelko
Mon, 16 Jun 2014 17:13:58 +0400
changeset 25197 533f45be322f
parent 9446 748a37b25d10
permissions -rw-r--r--
8046221: [TEST_BUG] Cleanup datatransfer tests Reviewed-by: anthony, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     1
/*
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     2
 * Copyright (c) 2011 Hewlett-Packard Company. All rights reserved.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     4
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     8
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    13
 * accompanied this code).
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    14
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    18
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    21
 * questions.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    22
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    23
 */
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    24
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    25
/**
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    26
 * @test
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    27
 * @bug 5091921
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    28
 * @summary Sign flip issues in loop optimizer
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    29
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    30
 * @run main/othervm -Xcomp -XX:CompileOnly=Test5091921 -XX:MaxInlineSize=1 Test5091921
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    31
 */
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    32
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    33
public class Test5091921 {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    34
  private static int result = 0;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    35
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    36
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    37
  /* Test for the bug of transforming indx >= MININT to indx > MININT-1 */
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    38
  public static int test_ge1(int limit) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    39
    int indx;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    40
    int sum = 0;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    41
    for (indx = 500; indx >= limit; indx -= 2) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    42
      sum += 2000 / indx;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    43
      result = sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    44
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    45
    return sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    46
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    47
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    48
  /* Test for the bug of transforming indx <= MAXINT to indx < MAXINT+1 */
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    49
  public static int test_le1(int limit) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    50
    int indx;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    51
    int sum = 0;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    52
    for (indx = -500; indx <= limit; indx += 2)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    53
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    54
      sum += 3000 / indx;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    55
      result = sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    56
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    57
    return sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    58
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    59
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    60
  /* Run with -Xcomp -XX:CompileOnly=wrap1.test1 -XX:MaxInlineSize=1 */
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    61
  /* limit reset to ((limit-init+stride-1)/stride)*stride+init */
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    62
  /* Calculation may overflow */
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    63
  public static volatile int c = 1;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    64
  public static int test_wrap1(int limit)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    65
  {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    66
    int indx;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    67
    int sum = 0;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    68
    for (indx = 0xffffffff; indx < limit; indx += 0x20000000)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    69
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    70
      sum += c;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    71
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    72
    return sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    73
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    74
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    75
  /* Test for range check elimination with bit flip issue for
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    76
     scale*i+offset<limit where offset is not 0 */
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    77
  static int[] box5 = {1,2,3,4,5,6,7,8,9};
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    78
  public static int test_rce5(int[] b, int limit)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    79
  {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    80
    int indx;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    81
    int sum = b[1];
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    82
    result = sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    83
    for (indx = 0x80000000; indx < limit; ++indx)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    84
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    85
      if (indx > 0x80000000)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    86
      {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    87
        // this test is not issued in pre-loop but issued in main loop
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    88
        // trick rce into thinking expression is false when indx >= 0
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    89
        // in fact it is false when indx==0x80000001
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    90
        if (indx - 9 < -9)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    91
        {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    92
          sum += indx;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    93
          result = sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    94
          sum ^= b[indx & 7];
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    95
          result = sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    96
        }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    97
        else
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    98
          break;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    99
      }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   100
      else
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   101
      {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   102
        sum += b[indx & 3];
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   103
        result = sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   104
      }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   105
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   106
    return sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   107
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   108
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   109
  /* Test for range check elimination with bit flip issue for
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   110
     scale*i<limit where scale > 1 */
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   111
  static int[] box6 = {1,2,3,4,5,6,7,8,9};
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   112
  public static int test_rce6(int[] b, int limit)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   113
  {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   114
    int indx;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   115
    int sum = b[1];
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   116
    result = sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   117
    for (indx = 0x80000000; indx < limit; ++indx)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   118
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   119
      if (indx > 0x80000000)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   120
      {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   121
        // harmless rce target
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   122
        if (indx < 0)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   123
        {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   124
          sum += result;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   125
          result = sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   126
        }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   127
        else
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   128
          break;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   129
        // this test is not issued in pre-loop but issued in main loop
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   130
        // trick rce into thinking expression is false when indx >= 0
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   131
        // in fact it is false when indx==0x80000001
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   132
        // In compilers that transform mulI to shiftI may mask this issue.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   133
        if (indx * 28 + 1 < 0)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   134
        {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   135
          sum += indx;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   136
          result = sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   137
          sum ^= b[indx & 7];
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   138
          result = sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   139
        }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   140
        else
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   141
          break;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   142
      }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   143
      else
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   144
      {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   145
        sum += b[indx & 3];
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   146
        result = sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   147
      }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   148
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   149
    return sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   150
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   151
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   152
  /* Test for range check elimination with i <= limit */
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   153
  static int[] box7 = {1,2,3,4,5,6,7,8,9,0x7fffffff};
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   154
  public static int test_rce7(int[] b)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   155
  {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   156
    int indx;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   157
    int max = b[9];
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   158
    int sum = b[7];
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   159
    result = sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   160
    for (indx = 0; indx < b.length; ++indx)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   161
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   162
      if (indx <= max)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   163
      {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   164
        sum += (indx ^ 15) + ((result != 0) ? 0 : sum);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   165
        result = sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   166
      }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   167
      else
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   168
        throw new RuntimeException();
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   169
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   170
    for (indx = -7; indx < b.length; ++indx)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   171
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   172
      if (indx <= 9)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   173
      {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   174
        sum += (sum ^ 15) + ((result != 0) ? 0 : sum);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   175
        result = sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   176
      }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   177
      else
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   178
        throw new RuntimeException();
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   179
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   180
    return sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   181
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   182
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   183
  /* Test for range check elimination with i >= limit */
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   184
  static int[] box8 = {-1,0,1,2,3,4,5,6,7,8,0x80000000};
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   185
  public static int test_rce8(int[] b)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   186
  {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   187
    int indx;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   188
    int sum = b[5];
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   189
    int min = b[10];
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   190
    result = sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   191
    for (indx = b.length-1; indx >= 0; --indx)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   192
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   193
      if (indx >= min)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   194
      {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   195
        sum += (sum ^ 9) + ((result != 0) ? 0 :sum);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   196
        result = sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   197
      }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   198
      else
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   199
        throw new RuntimeException();
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   200
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   201
    return sum;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   202
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   203
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   204
  public static void main(String[] args)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   205
  {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   206
    result=1;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   207
    int r = 0;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   208
    try {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   209
      r = test_ge1(0x80000000);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   210
      System.out.println(result);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   211
      System.out.println("test_ge1 FAILED");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   212
      System.exit(1);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   213
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   214
    catch (ArithmeticException e1) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   215
      System.out.println("test_ge1: Expected exception caught");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   216
      if (result != 5986) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   217
        System.out.println(result);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   218
        System.out.println("test_ge1 FAILED");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   219
        System.exit(97);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   220
      }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   221
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   222
    System.out.println("test_ge1 WORKED");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   223
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   224
    result=0;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   225
    try
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   226
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   227
      r = test_le1(0x7fffffff);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   228
      System.out.println(result);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   229
      System.out.println("test_le1 FAILED");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   230
      System.exit(1);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   231
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   232
    catch (ArithmeticException e1)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   233
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   234
      System.out.println("test_le1: Expected exception caught");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   235
      if (result != -9039)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   236
      {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   237
        System.out.println(result);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   238
        System.out.println("test_le1 FAILED");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   239
        System.exit(97);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   240
      }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   241
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   242
    System.out.println("test_le1 WORKED");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   243
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   244
    result=0;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   245
    r = test_wrap1(0x7fffffff);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   246
    if (r != 4)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   247
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   248
      System.out.println(result);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   249
      System.out.println("test_wrap1 FAILED");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   250
      System.exit(97);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   251
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   252
    else
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   253
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   254
      System.out.println("test_wrap1 WORKED");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   255
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   256
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   257
    result=0;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   258
    r = test_rce5(box5,0x80000100);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   259
    if (result != 3)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   260
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   261
      System.out.println(result);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   262
      System.out.println("test_rce5 FAILED");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   263
      System.exit(97);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   264
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   265
    else
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   266
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   267
      System.out.println("test_rce5 WORKED");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   268
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   269
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   270
    result=0;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   271
    r = test_rce6(box6,0x80000100);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   272
    if (result != 6)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   273
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   274
      System.out.println(result);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   275
      System.out.println("test_rce6 FAILED");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   276
      System.exit(97);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   277
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   278
    else
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   279
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   280
      System.out.println("test_rce6 WORKED");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   281
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   282
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   283
    result=0;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   284
    r = test_rce7(box7);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   285
    if (result != 14680079)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   286
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   287
      System.out.println(result);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   288
      System.out.println("test_rce7 FAILED");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   289
      System.exit(97);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   290
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   291
    else
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   292
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   293
      System.out.println("test_rce7 WORKED");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   294
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   295
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   296
    result=0;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   297
    r = test_rce8(box8);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   298
    if (result != 16393)
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   299
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   300
      System.out.println(result);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   301
      System.out.println("test_rce8 FAILED");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   302
      System.exit(97);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   303
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   304
    else
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   305
    {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   306
      System.out.println("test_rce8 WORKED");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   307
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   308
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   309
}