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 long operations.
031 */
032public class VN_Long03 extends JTTTest {
033
034    private static boolean cond = true;
035
036    public static long 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 long add(long x) {
065        long t = x + 3;
066        if (cond) {
067            long u = x + 3;
068            return t + u;
069        }
070        return 3;
071    }
072
073    public static long sub(long x) {
074        long t = x - 3;
075        if (cond) {
076            long u = x - 3;
077            return t - u;
078        }
079        return 3;
080    }
081
082    public static long mul(long x) {
083        long t = x * 3;
084        if (cond) {
085            long u = x * 3;
086            return t * u;
087        }
088        return 3;
089    }
090
091    public static long div(long x) {
092        long t = 9 / x;
093        if (cond) {
094            long u = 9 / x;
095            return t / u;
096        }
097        return 9;
098    }
099
100    public static long mod(long x) {
101        long t = 7 % x;
102        if (cond) {
103            long u = 7 % x;
104            return t % u;
105        }
106        return 7;
107    }
108
109    public static long and(long x) {
110        long t = 7 & x;
111        if (cond) {
112            long u = 7 & x;
113            return t & u;
114        }
115        return 7;
116    }
117
118    public static long or(long x) {
119        long t = 7 | x;
120        if (cond) {
121            long u = 7 | x;
122            return t | u;
123        }
124        return 7;
125    }
126
127    public static long xor(long x) {
128        long t = 7 ^ x;
129        if (cond) {
130            long u = 7 ^ x;
131            return t ^ u;
132        }
133        return 7;
134    }
135
136    @Test
137    public void run0() throws Throwable {
138        runTest("test", 0);
139    }
140
141    @Test
142    public void run1() throws Throwable {
143        runTest("test", 1);
144    }
145
146    @Test
147    public void run2() throws Throwable {
148        runTest("test", 2);
149    }
150
151    @Test
152    public void run3() throws Throwable {
153        runTest("test", 3);
154    }
155
156    @Test
157    public void run4() throws Throwable {
158        runTest("test", 4);
159    }
160
161    @Test
162    public void run5() throws Throwable {
163        runTest("test", 5);
164    }
165
166    @Test
167    public void run6() throws Throwable {
168        runTest("test", 6);
169    }
170
171    @Test
172    public void run7() throws Throwable {
173        runTest("test", 7);
174    }
175
176}