Reduce_Long01.java revision 12657:6ef01bd40ce2
138465Smsmith/*
238465Smsmith * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
338465Smsmith * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
438465Smsmith *
538465Smsmith * This code is free software; you can redistribute it and/or modify it
638465Smsmith * under the terms of the GNU General Public License version 2 only, as
738465Smsmith * published by the Free Software Foundation.
838465Smsmith *
938465Smsmith * This code is distributed in the hope that it will be useful, but WITHOUT
1038465Smsmith * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1138465Smsmith * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1238465Smsmith * version 2 for more details (a copy is included in the LICENSE file that
1338465Smsmith * accompanied this code).
1438465Smsmith *
1538465Smsmith * You should have received a copy of the GNU General Public License version
1638465Smsmith * 2 along with this work; if not, write to the Free Software Foundation,
1738465Smsmith * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1838465Smsmith *
1938465Smsmith * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2038465Smsmith * or visit www.oracle.com if you need additional information or have any
2138465Smsmith * questions.
2238465Smsmith */
2338465Smsmithpackage org.graalvm.compiler.jtt.optimize;
2438465Smsmith
2538465Smsmithimport org.junit.Test;
2639441Smsmith
2738465Smsmithimport org.graalvm.compiler.jtt.JTTTest;
2838465Smsmith
2938465Smsmith/*
3038465Smsmith * Tests constant folding of integer operations.
3138465Smsmith */
3238465Smsmithpublic class Reduce_Long01 extends JTTTest {
3338465Smsmith
3438465Smsmith    public static long test(long arg) {
3538465Smsmith        if (arg == 0) {
3638465Smsmith            return add(10);
3738465Smsmith        }
3838465Smsmith        if (arg == 1) {
3938465Smsmith            return sub(11);
4038465Smsmith        }
4138465Smsmith        if (arg == 2) {
4238465Smsmith            return mul(12);
4338465Smsmith        }
4438465Smsmith        if (arg == 3) {
4538465Smsmith            return div(13);
4638465Smsmith        }
4738465Smsmith        if (arg == 4) {
4838465Smsmith            return mod();
4938465Smsmith        }
5038465Smsmith        if (arg == 5) {
5138465Smsmith            return and(15);
5238465Smsmith        }
5338465Smsmith        if (arg == 6) {
5438465Smsmith            return or(16);
5538465Smsmith        }
5638465Smsmith        if (arg == 7) {
5738465Smsmith            return xor(17);
5838465Smsmith        }
5938465Smsmith        return 0;
6039178Smsmith    }
6138465Smsmith
6238465Smsmith    public static long add(long x) {
6338465Smsmith        return x + 0;
6438465Smsmith    }
6538465Smsmith
6638465Smsmith    public static long sub(long x) {
6738465Smsmith        return x - 0;
6838465Smsmith    }
6938465Smsmith
7038465Smsmith    public static long mul(long x) {
7138465Smsmith        return x * 1;
7238465Smsmith    }
7338465Smsmith
7438465Smsmith    public static long div(long x) {
7538465Smsmith        return x / 1;
7638465Smsmith    }
7738465Smsmith
7838465Smsmith    public static long mod() {
7938465Smsmith        return 14;
8038465Smsmith    }
8138465Smsmith
8238465Smsmith    public static long and(long x) {
8338465Smsmith        return x & -1;
8438465Smsmith    }
8538465Smsmith
8638465Smsmith    public static long or(long x) {
8738465Smsmith        return x | 0;
8838465Smsmith    }
8938465Smsmith
9038465Smsmith    public static long xor(long x) {
9138465Smsmith        return x ^ 0;
9238465Smsmith    }
9338465Smsmith
9438465Smsmith    @Test
9538465Smsmith    public void run0() throws Throwable {
9638465Smsmith        runTest("test", 0L);
9738465Smsmith    }
9839178Smsmith
9939178Smsmith    @Test
10038465Smsmith    public void run1() throws Throwable {
10138465Smsmith        runTest("test", 1L);
10239178Smsmith    }
10338465Smsmith
10438465Smsmith    @Test
10538465Smsmith    public void run2() throws Throwable {
10638465Smsmith        runTest("test", 2L);
10738465Smsmith    }
10838465Smsmith
10938465Smsmith    @Test
11038465Smsmith    public void run3() throws Throwable {
11138465Smsmith        runTest("test", 3L);
11238465Smsmith    }
11338465Smsmith
11438465Smsmith    @Test
11538465Smsmith    public void run4() throws Throwable {
11638465Smsmith        runTest("test", 4L);
11738465Smsmith    }
11838465Smsmith
11938465Smsmith    @Test
12038465Smsmith    public void run5() throws Throwable {
12138465Smsmith        runTest("test", 5L);
12238465Smsmith    }
12339441Smsmith
12438465Smsmith    @Test
12539441Smsmith    public void run6() throws Throwable {
12638465Smsmith        runTest("test", 6L);
12738465Smsmith    }
12839441Smsmith
12938465Smsmith    @Test
13038465Smsmith    public void run7() throws Throwable {
13139441Smsmith        runTest("test", 7L);
13238465Smsmith    }
13338465Smsmith
13439441Smsmith}
13538465Smsmith