001/*
002 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.jtt.optimize;
024
025import org.junit.*;
026
027import com.oracle.graal.jtt.*;
028
029/*
030 * Tests value numbering of integer operations.
031 */
032public class VN_Int03 extends JTTTest {
033
034    private static boolean cond = true;
035
036    public static int test(int arg) {
037        if (arg == 0) {
038            return add(arg);
039        }
040        if (arg == 1) {
041            return sub(arg);
042        }
043        if (arg == 2) {
044            return mul(arg);
045        }
046        if (arg == 3) {
047            return div(arg);
048        }
049        if (arg == 4) {
050            return mod(arg);
051        }
052        if (arg == 5) {
053            return and(arg);
054        }
055        if (arg == 6) {
056            return or(arg);
057        }
058        if (arg == 7) {
059            return xor(arg);
060        }
061        return 0;
062    }
063
064    public static int add(int x) {
065        int c = 3;
066        int t = x + c;
067        if (cond) {
068            int u = x + c;
069            return t + u;
070        }
071        return 0;
072    }
073
074    public static int sub(int x) {
075        int c = 3;
076        int t = x - c;
077        if (cond) {
078            int u = x - c;
079            return t - u;
080        }
081        return 3;
082    }
083
084    public static int mul(int x) {
085        int i = 3;
086        int t = x * i;
087        if (cond) {
088            int u = x * i;
089            return t * u;
090        }
091        return 3;
092    }
093
094    public static int div(int x) {
095        int i = 9;
096        int t = i / x;
097        if (cond) {
098            int u = i / x;
099            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}