1/*
2 * Copyright (c) 2009, 2012, 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.jtt.optimize;
24
25import org.junit.Test;
26
27import org.graalvm.compiler.jtt.JTTTest;
28
29/*
30 * Tests value numbering of integer operations.
31 */
32public class VN_Int03 extends JTTTest {
33
34    private static boolean cond = true;
35
36    public static int test(int arg) {
37        if (arg == 0) {
38            return add(arg);
39        }
40        if (arg == 1) {
41            return sub(arg);
42        }
43        if (arg == 2) {
44            return mul(arg);
45        }
46        if (arg == 3) {
47            return div(arg);
48        }
49        if (arg == 4) {
50            return mod(arg);
51        }
52        if (arg == 5) {
53            return and(arg);
54        }
55        if (arg == 6) {
56            return or(arg);
57        }
58        if (arg == 7) {
59            return xor(arg);
60        }
61        return 0;
62    }
63
64    public static int add(int x) {
65        int c = 3;
66        int t = x + c;
67        if (cond) {
68            int u = x + c;
69            return t + u;
70        }
71        return 0;
72    }
73
74    public static int sub(int x) {
75        int c = 3;
76        int t = x - c;
77        if (cond) {
78            int u = x - c;
79            return t - u;
80        }
81        return 3;
82    }
83
84    public static int mul(int x) {
85        int i = 3;
86        int t = x * i;
87        if (cond) {
88            int u = x * i;
89            return t * u;
90        }
91        return 3;
92    }
93
94    public static int div(int x) {
95        int i = 9;
96        int t = i / x;
97        if (cond) {
98            int u = i / x;
99            return t / u;
100        }
101        return 9;
102    }
103
104    public static int mod(int x) {
105        int i = 7;
106        int t = i % x;
107        if (cond) {
108            int u = i % x;
109            return t % u;
110        }
111        return 7;
112    }
113
114    public static int and(int x) {
115        int i = 7;
116        int t = i & x;
117        if (cond) {
118            int u = i & x;
119            return t & u;
120        }
121        return 7;
122    }
123
124    public static int or(int x) {
125        int i = 7;
126        int t = i | x;
127        if (cond) {
128            int u = i | x;
129            return t | u;
130        }
131        return 7;
132    }
133
134    public static int xor(int x) {
135        int i = 7;
136        int t = i ^ x;
137        if (cond) {
138            int u = i ^ x;
139            return t ^ u;
140        }
141        return 7;
142    }
143
144    @Test
145    public void run0() throws Throwable {
146        runTest("test", 0);
147    }
148
149    @Test
150    public void run1() throws Throwable {
151        runTest("test", 1);
152    }
153
154    @Test
155    public void run2() throws Throwable {
156        runTest("test", 2);
157    }
158
159    @Test
160    public void run3() throws Throwable {
161        runTest("test", 3);
162    }
163
164    @Test
165    public void run4() throws Throwable {
166        runTest("test", 4);
167    }
168
169    @Test
170    public void run5() throws Throwable {
171        runTest("test", 5);
172    }
173
174    @Test
175    public void run6() throws Throwable {
176        runTest("test", 6);
177    }
178
179    @Test
180    public void run7() throws Throwable {
181        runTest("test", 7);
182    }
183
184}
185