Fold_Convert02.java revision 12657:6ef01bd40ce2
1109998Smarkm/* 2109998Smarkm * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 3109998Smarkm * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4109998Smarkm * 5109998Smarkm * This code is free software; you can redistribute it and/or modify it 6109998Smarkm * under the terms of the GNU General Public License version 2 only, as 7109998Smarkm * published by the Free Software Foundation. 8109998Smarkm * 9109998Smarkm * This code is distributed in the hope that it will be useful, but WITHOUT 10109998Smarkm * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11109998Smarkm * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12109998Smarkm * version 2 for more details (a copy is included in the LICENSE file that 13109998Smarkm * accompanied this code). 14109998Smarkm * 15109998Smarkm * You should have received a copy of the GNU General Public License version 16109998Smarkm * 2 along with this work; if not, write to the Free Software Foundation, 17109998Smarkm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18109998Smarkm * 19109998Smarkm * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20109998Smarkm * or visit www.oracle.com if you need additional information or have any 21109998Smarkm * questions. 22109998Smarkm */ 23109998Smarkmpackage org.graalvm.compiler.jtt.optimize; 24109998Smarkm 25109998Smarkmimport org.junit.Test; 26109998Smarkm 27109998Smarkmimport org.graalvm.compiler.jtt.JTTTest; 28109998Smarkm 29109998Smarkm/* 30109998Smarkm * Tests constant folding of integer operations. 31109998Smarkm */ 32109998Smarkmpublic class Fold_Convert02 extends JTTTest { 33109998Smarkm 34109998Smarkm public static long test(long arg) { 35109998Smarkm if (arg == 0) { 36109998Smarkm return i2l(); 37109998Smarkm } 38109998Smarkm if (arg == 1) { 39109998Smarkm return f2l(); 40109998Smarkm } 41109998Smarkm if (arg == 2) { 42109998Smarkm return d2l(); 43109998Smarkm } 44109998Smarkm return 0; 45109998Smarkm } 46109998Smarkm 47109998Smarkm public static long i2l() { 48109998Smarkm int x = 0x80000000; 49109998Smarkm return x; 50109998Smarkm } 51109998Smarkm 52109998Smarkm public static long f2l() { 53109998Smarkm float x = -33.1f; 54109998Smarkm return (long) x; 55109998Smarkm } 56109998Smarkm 57109998Smarkm public static long d2l() { 58109998Smarkm double x = -78.1d; 59109998Smarkm return (long) x; 60109998Smarkm } 61109998Smarkm 62109998Smarkm @Test 63109998Smarkm public void run0() throws Throwable { 64109998Smarkm runTest("test", 0L); 65109998Smarkm } 66109998Smarkm 67109998Smarkm @Test 68109998Smarkm public void run1() throws Throwable { 69109998Smarkm runTest("test", 1L); 70109998Smarkm } 71109998Smarkm 72109998Smarkm @Test 73109998Smarkm public void run2() throws Throwable { 74 runTest("test", 2L); 75 } 76 77} 78