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 package org.graalvm.compiler.core.test;
  24 
  25 import org.junit.Test;
  26 
  27 /**
  28  * Collection of tests for
  29  * {@link org.graalvm.compiler.phases.common.DominatorConditionalEliminationPhase} including those
  30  * that triggered bugs in this phase.
  31  */
  32 public class ConditionalEliminationTest6 extends ConditionalEliminationTestBase {
  33 
  34     public static final A constA = new A();
  35     public static final B constB = new B();
  36 
  37     static class A {
  38     }
  39 
  40     static class B {
  41     }
  42 
  43     @SuppressWarnings("all")
  44     public static B reference1Snippet(Object a, B b) {
  45         if (a == constA) {
  46             return b;
  47         }
  48         return null;
  49     }
  50 
  51     @SuppressWarnings("all")
  52     public static B test1Snippet(Object a, B b) {
  53         if (a == constA) {
  54             if (a == null) {
  55                 return null;
  56             } else {
  57                 return b;
  58             }
  59         }
  60         return null;
  61     }
  62 
  63     @Test
  64     public void test1() {
  65         testConditionalElimination("test1Snippet", "reference1Snippet");
  66     }
  67 
  68     @SuppressWarnings("all")
  69     public static B test2Snippet(Object a, B b) {
  70         if (a == constA) {
  71             if (a == constB) {
  72                 return null;
  73             } else {
  74                 return b;
  75             }
  76         }
  77         return null;
  78     }
  79 
  80     @Test
  81     public void test2() {
  82         testConditionalElimination("test2Snippet", "reference1Snippet");
  83     }
  84 
  85     @SuppressWarnings("all")
  86     public static B test3Snippet(Object a, B b) {
  87         if (a == constA) {
  88             if (a == b) {
  89                 return null;
  90             } else {
  91                 return b;
  92             }
  93         }
  94         return null;
  95     }
  96 
  97     @Test
  98     public void test3() {
  99         testConditionalElimination("test3Snippet", "reference1Snippet");
 100     }
 101 }