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