Search in sources :

Example 1 with IntegerExactArithmeticNode

use of org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode in project graal by oracle.

the class IntegerExactFoldTest method testFolding.

@Test
public void testFolding() {
    StructuredGraph graph = prepareGraph();
    IntegerStamp a = StampFactory.forInteger(bits, lowerBoundA, upperBoundA);
    IntegerStamp b = StampFactory.forInteger(bits, lowerBoundB, upperBoundB);
    List<ParameterNode> params = graph.getNodes(ParameterNode.TYPE).snapshot();
    params.get(0).replaceAtMatchingUsages(graph.addOrUnique(new PiNode(params.get(0), a)), x -> x instanceof IntegerExactArithmeticNode);
    params.get(1).replaceAtMatchingUsages(graph.addOrUnique(new PiNode(params.get(1), b)), x -> x instanceof IntegerExactArithmeticNode);
    Node originalNode = graph.getNodes().filter(x -> x instanceof IntegerExactArithmeticNode).first();
    assertNotNull("original node must be in the graph", originalNode);
    new CanonicalizerPhase().apply(graph, getDefaultHighTierContext());
    ValueNode node = findNode(graph);
    boolean overflowExpected = node instanceof IntegerExactArithmeticNode;
    IntegerStamp resultStamp = (IntegerStamp) node.stamp(NodeView.DEFAULT);
    operation.verifyOverflow(lowerBoundA, upperBoundA, lowerBoundB, upperBoundB, bits, overflowExpected, resultStamp);
}
Also used : GuardsStage(org.graalvm.compiler.nodes.StructuredGraph.GuardsStage) LoweringTool(org.graalvm.compiler.nodes.spi.LoweringTool) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) AllowAssumptions(org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions) ArrayList(java.util.ArrayList) IntegerExactArithmeticNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) Parameterized(org.junit.runners.Parameterized) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) IntegerExactArithmeticSplitNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticSplitNode) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) NodeView(org.graalvm.compiler.nodes.NodeView) Test(org.junit.Test) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) List(java.util.List) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Node(org.graalvm.compiler.graph.Node) Assert(org.junit.Assert) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) IntegerExactArithmeticNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) IntegerExactArithmeticSplitNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticSplitNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) ValueNode(org.graalvm.compiler.nodes.ValueNode) IntegerExactArithmeticNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) PiNode(org.graalvm.compiler.nodes.PiNode) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) Test(org.junit.Test)

Example 2 with IntegerExactArithmeticNode

use of org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode in project graal by oracle.

the class IntegerExactFoldTest method testFoldingAfterLowering.

@Test
public void testFoldingAfterLowering() {
    StructuredGraph graph = prepareGraph();
    Node originalNode = graph.getNodes().filter(x -> x instanceof IntegerExactArithmeticNode).first();
    assertNotNull("original node must be in the graph", originalNode);
    graph.setGuardsStage(GuardsStage.FIXED_DEOPTS);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    PhaseContext context = new PhaseContext(getProviders());
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    IntegerExactArithmeticSplitNode loweredNode = graph.getNodes().filter(IntegerExactArithmeticSplitNode.class).first();
    assertNotNull("the lowered node must be in the graph", loweredNode);
    loweredNode.getX().setStamp(StampFactory.forInteger(bits, lowerBoundA, upperBoundA));
    loweredNode.getY().setStamp(StampFactory.forInteger(bits, lowerBoundB, upperBoundB));
    new CanonicalizerPhase().apply(graph, context);
    ValueNode node = findNode(graph);
    boolean overflowExpected = node instanceof IntegerExactArithmeticSplitNode;
    IntegerStamp resultStamp = (IntegerStamp) node.stamp(NodeView.DEFAULT);
    operation.verifyOverflow(lowerBoundA, upperBoundA, lowerBoundB, upperBoundB, bits, overflowExpected, resultStamp);
}
Also used : GuardsStage(org.graalvm.compiler.nodes.StructuredGraph.GuardsStage) LoweringTool(org.graalvm.compiler.nodes.spi.LoweringTool) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) AllowAssumptions(org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions) ArrayList(java.util.ArrayList) IntegerExactArithmeticNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) Parameterized(org.junit.runners.Parameterized) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) IntegerExactArithmeticSplitNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticSplitNode) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) NodeView(org.graalvm.compiler.nodes.NodeView) Test(org.junit.Test) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) List(java.util.List) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Node(org.graalvm.compiler.graph.Node) Assert(org.junit.Assert) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) IntegerExactArithmeticNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) IntegerExactArithmeticSplitNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticSplitNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ValueNode(org.graalvm.compiler.nodes.ValueNode) IntegerExactArithmeticNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) IntegerExactArithmeticSplitNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticSplitNode) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)2 StampFactory (org.graalvm.compiler.core.common.type.StampFactory)2 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)2 Node (org.graalvm.compiler.graph.Node)2 NodeView (org.graalvm.compiler.nodes.NodeView)2 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)2 PiNode (org.graalvm.compiler.nodes.PiNode)2 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)2 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 AllowAssumptions (org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions)2 GuardsStage (org.graalvm.compiler.nodes.StructuredGraph.GuardsStage)2 ValueNode (org.graalvm.compiler.nodes.ValueNode)2 LoweringTool (org.graalvm.compiler.nodes.spi.LoweringTool)2 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)2 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)2 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)2 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)2