1 /*
   2  * Copyright (c) 2015, 2015, 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 package org.graalvm.compiler.core.test;
  26 
  27 import org.junit.Ignore;
  28 import org.junit.Test;
  29 
  30 /**
  31  * Collection of tests for {@link org.graalvm.compiler.phases.common.ConditionalEliminationPhase}
  32  * including those that triggered bugs in this phase.
  33  */
  34 @Ignore
  35 public class ConditionalEliminationTest3 extends ConditionalEliminationTestBase {
  36 
  37     private static final String REFERENCE_SNIPPET = "referenceSnippet";
  38 
  39     @SuppressWarnings("all")
  40     public static int referenceSnippet(int a, int b) {
  41         int sum = 0;
  42         outer: for (int i = 0;; ++i) {
  43             if (b > 100) {
  44                 inner: for (int j = 0;; ++j) {
  45                     ++sum;
  46                     if (sum == 100) {
  47                         break inner;
  48                     }
  49                     if (sum == 1000 && b < 1000) {
  50                         break outer;
  51                     }
  52                 }
  53             }
  54         }
  55         return sum;
  56     }
  57 
  58     @Test
  59     public void test1() {
  60         testConditionalElimination("test1Snippet", REFERENCE_SNIPPET);
  61     }
  62 
  63     @SuppressWarnings("all")
  64     public static int test1Snippet(int a, int b) {
  65         int sum = 0;
  66         outer: for (int i = 0;; ++i) {
  67             if (b > 100) {
  68                 inner: for (int j = 0;; ++j) {
  69                     ++sum;
  70                     if (sum == 100) {
  71                         break inner;
  72                     }
  73                     if (sum == 1000 && b < 1000) {
  74                         break outer;
  75                     }
  76                 }
  77             }
  78         }
  79         if (b >= 1000) {
  80             return 5;
  81         }
  82         return sum;
  83     }
  84 
  85     @Test
  86     public void test2() {
  87         testConditionalElimination("test2Snippet", REFERENCE_SNIPPET);
  88     }
  89 
  90     @SuppressWarnings("all")
  91     public static int test2Snippet(int a, int b) {
  92         int sum = 0;
  93         outer: for (int i = 0;; ++i) {
  94             if (b > 100) {
  95                 inner: for (int j = 0;; ++j) {
  96                     ++sum;
  97                     if (sum == 100) {
  98                         break inner;
  99                     }
 100                     if (sum == 1000 && b < 1000) {
 101                         break outer;
 102                     }
 103                 }
 104                 if (sum != 100) {
 105                     return 42;
 106                 }
 107             }
 108         }
 109         return sum;
 110     }
 111 }