src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ConditionalEliminationTest15.java
author dlong
Tue, 24 Sep 2019 12:47:15 -0400
changeset 58299 6df94ce3ab2f
parent 55509 d58442b8abc1
child 58679 9c3209ff7550
child 58877 aec7bf35d6f5
permissions -rw-r--r--
8229201: Update Graal Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50330
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
     1
/*
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
50330
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
     4
 *
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
     8
 *
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    13
 * accompanied this code).
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    14
 *
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    18
 *
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    21
 * questions.
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    22
 */
50858
2d3e99a72541 8205824: Update Graal
never
parents: 50330
diff changeset
    23
2d3e99a72541 8205824: Update Graal
never
parents: 50330
diff changeset
    24
50330
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    25
package org.graalvm.compiler.core.test;
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    26
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    27
import org.graalvm.compiler.debug.DebugContext;
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    28
import org.graalvm.compiler.graph.Node;
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    29
import org.graalvm.compiler.nodes.StructuredGraph;
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    30
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    31
import org.graalvm.compiler.nodes.calc.IntegerLessThanNode;
55509
d58442b8abc1 8225497: Update Graal
jwilhelm
parents: 50858
diff changeset
    32
import org.graalvm.compiler.nodes.spi.CoreProviders;
50330
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    33
import org.graalvm.compiler.nodes.spi.LoweringTool;
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    34
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    35
import org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase;
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    36
import org.graalvm.compiler.phases.common.LoweringPhase;
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    37
import org.graalvm.compiler.virtual.phases.ea.EarlyReadEliminationPhase;
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    38
import org.junit.Assert;
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    39
import org.junit.Test;
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    40
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    41
/**
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    42
 * Collection of tests for {@link org.graalvm.compiler.phases.common.ConditionalEliminationPhase}
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    43
 * including those that triggered bugs in this phase.
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    44
 */
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    45
public class ConditionalEliminationTest15 extends ConditionalEliminationTestBase {
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    46
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    47
    private void checkNodeCount(String methodName, Class<? extends Node> nodeClass, int count) {
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    48
        StructuredGraph graph = parseEager(methodName, AllowAssumptions.YES);
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    49
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    50
        CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
55509
d58442b8abc1 8225497: Update Graal
jwilhelm
parents: 50858
diff changeset
    51
        CoreProviders context = getProviders();
50330
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    52
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    53
        new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    54
        canonicalizer.apply(graph, context);
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    55
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    56
        // Merge arr.length reads.
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    57
        new EarlyReadEliminationPhase(canonicalizer).apply(graph, context);
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    58
        new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context);
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    59
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    60
        getDebugContext().dump(DebugContext.BASIC_LEVEL, graph, "After ConditionalEliminationPhase");
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    61
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    62
        Assert.assertEquals(count, graph.getNodes().filter(nodeClass).count());
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    63
    }
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    64
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    65
    public static int testRedundantIntegerLessThanNode(int index, int[] arr) {
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    66
        while (arr[index] != 42) {
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    67
            if (index >= 0) { // redundant
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    68
                return 1;
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    69
            }
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    70
        }
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    71
        return 2;
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    72
    }
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    73
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    74
    public static int testRedundantIntegerLessThanNode2(int index, int[] arr) {
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    75
        while (arr[index] != 42) {
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    76
            if (index < arr.length) { // redundant
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    77
                return 1;
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    78
            }
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    79
        }
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    80
        return 2;
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    81
    }
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    82
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    83
    @Test
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    84
    public void testRedundantSignedLessThanNode() {
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    85
        checkNodeCount("testRedundantIntegerLessThanNode", IntegerLessThanNode.class, 0);
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    86
        checkNodeCount("testRedundantIntegerLessThanNode2", IntegerLessThanNode.class, 0);
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    87
    }
2cbc42a5764b 8202670: Update Graal
dlong
parents:
diff changeset
    88
}