src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ConditionalEliminationTest14.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58299 6df94ce3ab2f
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47798
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
     1
/*
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 55509
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
47798
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
     4
 *
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
     8
 *
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    13
 * accompanied this code).
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    14
 *
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    18
 *
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    21
 * questions.
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    22
 */
50858
2d3e99a72541 8205824: Update Graal
never
parents: 47798
diff changeset
    23
2d3e99a72541 8205824: Update Graal
never
parents: 47798
diff changeset
    24
47798
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    25
package org.graalvm.compiler.core.test;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    26
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    27
import org.graalvm.compiler.graph.iterators.NodeIterable;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    28
import org.graalvm.compiler.nodes.ConstantNode;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    29
import org.graalvm.compiler.nodes.FixedGuardNode;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    30
import org.graalvm.compiler.nodes.GuardNode;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    31
import org.graalvm.compiler.nodes.LogicNode;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    32
import org.graalvm.compiler.nodes.StructuredGraph;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    33
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    34
import org.graalvm.compiler.nodes.calc.IntegerBelowNode;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    35
import org.graalvm.compiler.nodes.java.LoadIndexedNode;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    36
import org.graalvm.compiler.nodes.memory.FloatingReadNode;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    37
import org.graalvm.compiler.nodes.memory.ReadNode;
55509
d58442b8abc1 8225497: Update Graal
jwilhelm
parents: 52910
diff changeset
    38
import org.graalvm.compiler.nodes.spi.CoreProviders;
47798
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    39
import org.graalvm.compiler.nodes.spi.LoweringTool;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    40
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    41
import org.graalvm.compiler.phases.common.FloatingReadPhase;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    42
import org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    43
import org.graalvm.compiler.phases.common.LoweringPhase;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    44
import org.junit.Assert;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    45
import org.junit.Test;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    46
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    47
import jdk.vm.ci.meta.DeoptimizationReason;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    48
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    49
/**
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    50
 * Check that multiple bounds checks are correctly grouped together.
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    51
 */
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    52
public class ConditionalEliminationTest14 extends ConditionalEliminationTestBase {
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    53
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    54
    public static void test1Snippet(Object[] args) {
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    55
        Object a5 = args[5];
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    56
        Object a7 = args[7];
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    57
        Object a6 = args[6];
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    58
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    59
        /*
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    60
         * The order of the conditions matters: The scheduler processes the floating reads for the
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    61
         * array loads in the order of the conditions here, and we want the index 7 access to be
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    62
         * processed before the index 6 access.
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    63
         */
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    64
        if (a5 != null && a7 != null && a6 != null) {
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    65
            sink1 = 1;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    66
        }
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    67
        sink0 = 0;
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    68
    }
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    69
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    70
    @Test
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    71
    public void test1() {
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    72
        StructuredGraph graph = parseEager("test1Snippet", AllowAssumptions.YES);
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    73
        CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
55509
d58442b8abc1 8225497: Update Graal
jwilhelm
parents: 52910
diff changeset
    74
        CoreProviders context = getProviders();
47798
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    75
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    76
        /* Convert the LoadIndexNode to ReadNode with floating guards. */
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    77
        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    78
        /* Convert the ReadNode to FloatingReadNode. */
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    79
        new FloatingReadPhase().apply(graph);
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    80
        /* Apply the phase that we want to test. */
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    81
        new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context);
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    82
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    83
        Assert.assertEquals("All guards must be floating", 0, graph.getNodes(FixedGuardNode.TYPE).count());
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    84
        Assert.assertEquals("All array accesses must have been lowered", 0, graph.getNodes().filter(LoadIndexedNode.class).count());
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    85
        Assert.assertEquals("All reads must be floating", 0, graph.getNodes().filter(ReadNode.class).count());
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    86
        Assert.assertEquals("Must have floating reads (3 array accesses, 1 array length)", 4, graph.getNodes().filter(FloatingReadNode.class).count());
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    87
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    88
        NodeIterable<GuardNode> boundsChecks = graph.getNodes(GuardNode.TYPE).filter(n -> ((GuardNode) n).getReason() == DeoptimizationReason.BoundsCheckException);
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    89
        Assert.assertEquals("Must have only 1 bounds check remaining", 1, boundsChecks.count());
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    90
        LogicNode condition = boundsChecks.first().getCondition();
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    91
        Assert.assertTrue("Bounds check must check for array length 8", condition instanceof IntegerBelowNode && ((IntegerBelowNode) condition).getY().valueEquals(ConstantNode.forInt(8)));
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    92
    }
9fe9292f5931 8190710: Update Graal
dlong
parents:
diff changeset
    93
}