1 /* 2 * Copyright (c) 2013, 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 */ 23 24 /** 25 * @test 26 * @bug 6443505 27 * @summary Some cases for CmpLTMask missed; also wrong code. 28 * 29 * @run main/othervm -Xcomp 30 * -XX:CompileCommand=compileonly,compiler.c2.Test6443505::compiled 31 * compiler.c2.Test6443505 32 */ 33 34 package compiler.c2; 35 36 public class Test6443505 { 37 main(String[] args)38 public static void main(String[] args) throws InterruptedException { 39 test(Integer.MIN_VALUE, 0); 40 test(0, Integer.MIN_VALUE); 41 test(Integer.MIN_VALUE, -1); 42 test(-1, Integer.MIN_VALUE); 43 test(Integer.MIN_VALUE, 1); 44 test(1, Integer.MIN_VALUE); 45 46 test(Integer.MAX_VALUE, 0); 47 test(0, Integer.MAX_VALUE); 48 test(Integer.MAX_VALUE, -1); 49 test(-1, Integer.MAX_VALUE); 50 test(Integer.MAX_VALUE, 1); 51 test(1, Integer.MAX_VALUE); 52 53 test(Integer.MIN_VALUE, Integer.MAX_VALUE); 54 test(Integer.MAX_VALUE, Integer.MIN_VALUE); 55 56 test(1, -1); 57 test(1, 0); 58 test(1, 1); 59 test(-1, -1); 60 test(-1, 0); 61 test(-1, 1); 62 test(0, -1); 63 test(0, 0); 64 test(0, 1); 65 } 66 test(int a, int b)67 public static void test(int a, int b) throws InterruptedException { 68 int C = compiled(4, a, b); 69 int I = interpreted(4, a, b); 70 if (C != I) { 71 System.err.println("#1 C = " + C + ", I = " + I); 72 System.err.println("#1 C != I, FAIL"); 73 System.exit(97); 74 } 75 76 C = compiled(a, b, q, 4); 77 I = interpreted(a, b, q, 4); 78 if (C != I) { 79 System.err.println("#2 C = " + C + ", I = " + I); 80 System.err.println("#2 C != I, FAIL"); 81 System.exit(97); 82 } 83 84 } 85 86 static int q = 4; 87 88 // If improperly compiled, uses carry/borrow bit, which is wrong. 89 // with -XX:+PrintOptoAssembly, look for cadd_cmpLTMask compiled(int p, int x, int y)90 static int compiled(int p, int x, int y) { 91 return (x < y) ? q + (x - y) : (x - y); 92 } 93 94 // interpreted reference interpreted(int p, int x, int y)95 static int interpreted(int p, int x, int y) { 96 return (x < y) ? q + (x - y) : (x - y); 97 } 98 99 // Test new code with a range of cases 100 // with -XX:+PrintOptoAssembly, look for and_cmpLTMask compiled(int x, int y, int q, int p)101 static int compiled(int x, int y, int q, int p) { 102 return (x < y) ? p + q : q; 103 } 104 105 // interpreted reference interpreted(int x, int y, int q, int p)106 static int interpreted(int x, int y, int q, int p) { 107 return (x < y) ? p + q : q; 108 } 109 110 } 111