hotspot/test/compiler/6443505/Test6443505.java
author malenkov
Thu, 22 May 2014 21:05:30 +0400
changeset 25100 d527cc827d7d
parent 17008 fe66415573bf
permissions -rw-r--r--
8043627: NPE in SynthContext in plugin mode Reviewed-by: alexsch, serb, pchelko
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17008
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
     1
/*
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
     4
 *
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
     8
 *
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    13
 * accompanied this code).
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    14
 *
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    18
 *
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    21
 * questions.
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    22
 *
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    23
 */
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    24
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    25
/**
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    26
 * @test
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    27
 * @bug 6443505
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    28
 * @summary Some cases for CmpLTMask missed; also wrong code.
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    29
 *
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    30
 * @run main/othervm -Xcomp -XX:CompileOnly="Test6443505.compiled" Test6443505
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    31
 */
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    32
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    33
public class Test6443505 {
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    34
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    35
    public static void main(String[] args) throws InterruptedException {
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    36
        test(Integer.MIN_VALUE, 0);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    37
        test(0, Integer.MIN_VALUE);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    38
        test(Integer.MIN_VALUE, -1);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    39
        test(-1, Integer.MIN_VALUE);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    40
        test(Integer.MIN_VALUE, 1);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    41
        test(1, Integer.MIN_VALUE);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    42
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    43
        test(Integer.MAX_VALUE, 0);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    44
        test(0, Integer.MAX_VALUE);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    45
        test(Integer.MAX_VALUE, -1);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    46
        test(-1, Integer.MAX_VALUE);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    47
        test(Integer.MAX_VALUE, 1);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    48
        test(1, Integer.MAX_VALUE);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    49
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    50
        test(Integer.MIN_VALUE, Integer.MAX_VALUE);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    51
        test(Integer.MAX_VALUE, Integer.MIN_VALUE);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    52
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    53
        test(1, -1);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    54
        test(1, 0);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    55
        test(1, 1);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    56
        test(-1, -1);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    57
        test(-1, 0);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    58
        test(-1, 1);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    59
        test(0, -1);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    60
        test(0, 0);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    61
        test(0, 1);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    62
    }
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    63
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    64
    public static void test(int a, int b) throws InterruptedException {
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    65
        int C = compiled(4, a, b);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    66
        int I = interpreted(4, a, b);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    67
        if (C != I) {
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    68
            System.err.println("#1 C = " + C + ", I = " + I);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    69
            System.err.println("#1 C != I, FAIL");
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    70
            System.exit(97);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    71
        }
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    72
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    73
        C = compiled(a, b, q, 4);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    74
        I = interpreted(a, b, q, 4);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    75
        if (C != I) {
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    76
            System.err.println("#2 C = " + C + ", I = " + I);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    77
            System.err.println("#2 C != I, FAIL");
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    78
            System.exit(97);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    79
        }
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    80
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    81
    }
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    82
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    83
    static int q = 4;
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    84
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    85
    // If improperly compiled, uses carry/borrow bit, which is wrong.
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    86
    // with -XX:+PrintOptoAssembly, look for cadd_cmpLTMask
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    87
    static int compiled(int p, int x, int y) {
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    88
        return (x < y) ? q + (x - y) : (x - y);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    89
    }
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    90
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    91
    // interpreted reference
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    92
    static int interpreted(int p, int x, int y) {
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    93
        return (x < y) ? q + (x - y) : (x - y);
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    94
    }
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    95
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    96
    // Test new code with a range of cases
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    97
    // with -XX:+PrintOptoAssembly, look for and_cmpLTMask
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    98
    static int compiled(int x, int y, int q, int p) {
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
    99
        return (x < y) ? p + q : q;
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
   100
    }
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
   101
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
   102
    // interpreted reference
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
   103
    static int interpreted(int x, int y, int q, int p) {
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
   104
        return (x < y) ? p + q : q;
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
   105
    }
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
   106
fe66415573bf 6443505: Ideal() function for CmpLTMask
drchase
parents:
diff changeset
   107
}