1 /*
   2  * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 /**
  26  * @test
  27  * @bug 7110586
  28  * @summary C2 generates icorrect results
  29  *
  30  * @run main/othervm -Xbatch compiler.c2.Test7110586
  31  */
  32 
  33 package compiler.c2;
  34 
  35 public class Test7110586 {
  36   static int test1() {
  37     int i = 0;
  38     for ( ; i < 11; i+=1) {}
  39     return i;
  40   }
  41   static int test2() {
  42     int i = 0;
  43     for ( ; i < 11; i+=2) {}
  44     return i;
  45   }
  46   static int test3() {
  47     int i = 0;
  48     for ( ; i < 11; i+=3) {}
  49     return i;
  50   }
  51   static int test11() {
  52     int i = 0;
  53     for ( ; i < 11; i+=11) {}
  54     return i;
  55   }
  56 
  57   static int testm1() {
  58     int i = 0;
  59     for ( ; i > -11; i-=1) {}
  60     return i;
  61   }
  62   static int testm2() {
  63     int i = 0;
  64     for ( ; i > -11; i-=2) {}
  65     return i;
  66   }
  67   static int testm3() {
  68     int i = 0;
  69     for ( ; i > -11; i-=3) {}
  70     return i;
  71   }
  72   static int testm11() {
  73     int i = 0;
  74     for ( ; i > -11; i-=11) {}
  75     return i;
  76   }
  77 
  78   public static void main(String args[]) {
  79     int x1  = 0;
  80     int x2  = 0;
  81     int x3  = 0;
  82     int x11 = 0;
  83     int m1  = 0;
  84     int m2  = 0;
  85     int m3  = 0;
  86     int m11 = 0;
  87     for (int i=0; i<10000; i++) {
  88       x1  = test1();
  89       x2  = test2();
  90       x3  = test3();
  91       x11 = test11();
  92       m1  = testm1();
  93       m2  = testm2();
  94       m3  = testm3();
  95       m11 = testm11();
  96     }
  97     boolean failed = false;
  98     if (x1 != 11) {
  99       System.out.println("ERROR (incr = +1): " + x1 + " != 11");
 100       failed = true;
 101     }
 102     if (x2 != 12) {
 103       System.out.println("ERROR (incr = +2): " + x2 + " != 12");
 104       failed = true;
 105     }
 106     if (x3 != 12) {
 107       System.out.println("ERROR (incr = +3): " + x3 + " != 12");
 108       failed = true;
 109     }
 110     if (x11 != 11) {
 111       System.out.println("ERROR (incr = +11): " + x11 + " != 11");
 112       failed = true;
 113     }
 114     if (m1 != -11) {
 115       System.out.println("ERROR (incr = -1): " + m1 + " != -11");
 116       failed = true;
 117     }
 118     if (m2 != -12) {
 119       System.out.println("ERROR (incr = -2): " + m2 + " != -12");
 120       failed = true;
 121     }
 122     if (m3 != -12) {
 123       System.out.println("ERROR (incr = -3): " + m3 + " != -12");
 124       failed = true;
 125     }
 126     if (m11 != -11) {
 127       System.out.println("ERROR (incr = -11): " + m11 + " != -11");
 128       failed = true;
 129     }
 130     if (failed) {
 131       System.exit(97);
 132     }
 133   }
 134 }