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 long operations. 31 */ 32public class VN_Long03 extends JTTTest { 33 34 private static boolean cond = true; 35 36 public static long 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 long add(long x) { 65 long t = x + 3; 66 if (cond) { 67 long u = x + 3; 68 return t + u; 69 } 70 return 3; 71 } 72 73 public static long sub(long x) { 74 long t = x - 3; 75 if (cond) { 76 long u = x - 3; 77 return t - u; 78 } 79 return 3; 80 } 81 82 public static long mul(long x) { 83 long t = x * 3; 84 if (cond) { 85 long u = x * 3; 86 return t * u; 87 } 88 return 3; 89 } 90 91 public static long div(long x) { 92 long t = 9 / x; 93 if (cond) { 94 long u = 9 / x; 95 return t / u; 96 } 97 return 9; 98 } 99 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} 177