src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CompareCanonicalizerTest2.java
author dlong
Thu, 31 Oct 2019 16:54:16 -0700
changeset 58877 aec7bf35d6f5
parent 58299 6df94ce3ab2f
permissions -rw-r--r--
8233273: Update Graal Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
     1
/*
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
     2
 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
     4
 *
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
     8
 *
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    13
 * accompanied this code).
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    14
 *
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    18
 *
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    21
 * questions.
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    22
 */
50858
2d3e99a72541 8205824: Update Graal
never
parents: 47216
diff changeset
    23
2d3e99a72541 8205824: Update Graal
never
parents: 47216
diff changeset
    24
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    25
package org.graalvm.compiler.core.test;
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    26
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    27
import org.graalvm.compiler.nodes.StructuredGraph;
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    28
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    29
import org.junit.Test;
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    30
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    31
public class CompareCanonicalizerTest2 extends GraalCompilerTest {
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    32
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    33
    @SuppressWarnings("unused") private static boolean sink;
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    34
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    35
    private StructuredGraph getCanonicalizedGraph(String name) {
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    36
        StructuredGraph graph = getRegularGraph(name);
58877
aec7bf35d6f5 8233273: Update Graal
dlong
parents: 58299
diff changeset
    37
        createCanonicalizerPhase().apply(graph, getProviders());
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    38
        return graph;
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    39
    }
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    40
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    41
    private StructuredGraph getRegularGraph(String name) {
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    42
        StructuredGraph graph = parseEager(name, AllowAssumptions.YES);
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    43
        return graph;
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    44
    }
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    45
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    46
    @Test
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    47
    public void test0() {
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    48
        assertEquals(getCanonicalizedGraph("integerTestCanonicalization0"), getRegularGraph("integerTestCanonicalization0"));
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    49
    }
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    50
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    51
    public static void integerTestCanonicalization0(int a) {
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    52
        sink = 1 < a + 1;
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    53
    }
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    54
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    55
    @Test
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    56
    public void test1() {
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    57
        assertEquals(getCanonicalizedGraph("integerTestCanonicalization1"), getRegularGraph("integerTestCanonicalization1"));
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    58
    }
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    59
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    60
    public static void integerTestCanonicalization1(int a) {
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    61
        sink = a - 1 < -1;
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    62
    }
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    63
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    64
    @Test
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    65
    public void test2() {
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    66
        assertEquals(getCanonicalizedGraph("integerTestCanonicalization2a"), getCanonicalizedGraph("integerTestCanonicalization2Reference"));
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    67
        assertEquals(getCanonicalizedGraph("integerTestCanonicalization2b"), getCanonicalizedGraph("integerTestCanonicalization2Reference"));
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    68
    }
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    69
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    70
    public static boolean integerTestCanonicalization2a(Object[] arr) {
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    71
        return arr.length - 1 < 0;
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    72
    }
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    73
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    74
    public static boolean integerTestCanonicalization2b(Object[] arr) {
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    75
        return arr.length < 1;
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    76
    }
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    77
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    78
    public static boolean integerTestCanonicalization2Reference(Object[] arr) {
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    79
        return arr.length == 0;
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    80
    }
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    81
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    82
    @Test
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    83
    public void test3() {
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    84
        assertEquals(getCanonicalizedGraph("integerTestCanonicalization3"), getCanonicalizedGraph("integerTestCanonicalization3Reference"));
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    85
    }
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    86
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    87
    public static boolean integerTestCanonicalization3(Object[] arr) {
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    88
        return ((long) (arr.length - 1)) - 1 < 0;
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    89
    }
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    90
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    91
    public static boolean integerTestCanonicalization3Reference(Object[] arr) {
7dd81e82d083 8210777: Update Graal
dlong
parents: 50858
diff changeset
    92
        return arr.length < 2;
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    93
    }
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    94
694c102fd8ed 8177046: Update Graal
iveresov
parents:
diff changeset
    95
}