src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/IntegerExactFoldTest.java
changeset 58877 aec7bf35d6f5
parent 58299 6df94ce3ab2f
equal deleted inserted replaced
58876:1a8d65e71a66 58877:aec7bf35d6f5
    92         params.get(1).replaceAtMatchingUsages(graph.addOrUnique(new PiNode(params.get(1), b)), x -> x instanceof IntegerExactArithmeticNode);
    92         params.get(1).replaceAtMatchingUsages(graph.addOrUnique(new PiNode(params.get(1), b)), x -> x instanceof IntegerExactArithmeticNode);
    93 
    93 
    94         Node originalNode = graph.getNodes().filter(x -> x instanceof IntegerExactArithmeticNode).first();
    94         Node originalNode = graph.getNodes().filter(x -> x instanceof IntegerExactArithmeticNode).first();
    95         assertNotNull("original node must be in the graph", originalNode);
    95         assertNotNull("original node must be in the graph", originalNode);
    96 
    96 
    97         new CanonicalizerPhase().apply(graph, getDefaultHighTierContext());
    97         createCanonicalizerPhase().apply(graph, getDefaultHighTierContext());
    98 
    98 
    99         ValueNode node = findNode(graph);
    99         ValueNode node = findNode(graph);
   100         boolean overflowExpected = node instanceof IntegerExactArithmeticNode;
   100         boolean overflowExpected = node instanceof IntegerExactArithmeticNode;
   101 
   101 
   102         IntegerStamp resultStamp = (IntegerStamp) node.stamp(NodeView.DEFAULT);
   102         IntegerStamp resultStamp = (IntegerStamp) node.stamp(NodeView.DEFAULT);
   107     public void testFoldingAfterLowering() {
   107     public void testFoldingAfterLowering() {
   108         StructuredGraph graph = prepareGraph();
   108         StructuredGraph graph = prepareGraph();
   109 
   109 
   110         Node originalNode = graph.getNodes().filter(x -> x instanceof IntegerExactArithmeticNode).first();
   110         Node originalNode = graph.getNodes().filter(x -> x instanceof IntegerExactArithmeticNode).first();
   111         assertNotNull("original node must be in the graph", originalNode);
   111         assertNotNull("original node must be in the graph", originalNode);
   112         CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
   112         CanonicalizerPhase canonicalizer = createCanonicalizerPhase();
   113         HighTierContext highTierContext = getDefaultHighTierContext();
   113         HighTierContext highTierContext = getDefaultHighTierContext();
   114         new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, highTierContext);
   114         new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, highTierContext);
   115         MidTierContext midTierContext = getDefaultMidTierContext();
   115         MidTierContext midTierContext = getDefaultMidTierContext();
   116         new GuardLoweringPhase().apply(graph, midTierContext);
   116         new GuardLoweringPhase().apply(graph, midTierContext);
   117         new CanonicalizerPhase().apply(graph, midTierContext);
   117         createCanonicalizerPhase().apply(graph, midTierContext);
   118 
   118 
   119         IntegerExactArithmeticSplitNode loweredNode = graph.getNodes().filter(IntegerExactArithmeticSplitNode.class).first();
   119         IntegerExactArithmeticSplitNode loweredNode = graph.getNodes().filter(IntegerExactArithmeticSplitNode.class).first();
   120         assertNotNull("the lowered node must be in the graph", loweredNode);
   120         assertNotNull("the lowered node must be in the graph", loweredNode);
   121 
   121 
   122         loweredNode.getX().setStamp(StampFactory.forInteger(bits, lowerBoundA, upperBoundA));
   122         loweredNode.getX().setStamp(StampFactory.forInteger(bits, lowerBoundA, upperBoundA));
   123         loweredNode.getY().setStamp(StampFactory.forInteger(bits, lowerBoundB, upperBoundB));
   123         loweredNode.getY().setStamp(StampFactory.forInteger(bits, lowerBoundB, upperBoundB));
   124         new CanonicalizerPhase().apply(graph, midTierContext);
   124         createCanonicalizerPhase().apply(graph, midTierContext);
   125 
   125 
   126         ValueNode node = findNode(graph);
   126         ValueNode node = findNode(graph);
   127         boolean overflowExpected = node instanceof IntegerExactArithmeticSplitNode;
   127         boolean overflowExpected = node instanceof IntegerExactArithmeticSplitNode;
   128 
   128 
   129         IntegerStamp resultStamp = (IntegerStamp) node.stamp(NodeView.DEFAULT);
   129         IntegerStamp resultStamp = (IntegerStamp) node.stamp(NodeView.DEFAULT);
   142 
   142 
   143     protected StructuredGraph prepareGraph() {
   143     protected StructuredGraph prepareGraph() {
   144         String snippet = "snippetInt" + bits;
   144         String snippet = "snippetInt" + bits;
   145         StructuredGraph graph = parseEager(getResolvedJavaMethod(operation.getClass(), snippet), AllowAssumptions.NO);
   145         StructuredGraph graph = parseEager(getResolvedJavaMethod(operation.getClass(), snippet), AllowAssumptions.NO);
   146         HighTierContext context = getDefaultHighTierContext();
   146         HighTierContext context = getDefaultHighTierContext();
   147         new CanonicalizerPhase().apply(graph, context);
   147         createCanonicalizerPhase().apply(graph, context);
   148         return graph;
   148         return graph;
   149     }
   149     }
   150 
   150 
   151     private static void addTest(ArrayList<Object[]> tests, long lowerBound1, long upperBound1, long lowerBound2, long upperBound2, int bits, Operation operation) {
   151     private static void addTest(ArrayList<Object[]> tests, long lowerBound1, long upperBound1, long lowerBound2, long upperBound2, int bits, Operation operation) {
   152         tests.add(new Object[]{lowerBound1, upperBound1, lowerBound2, upperBound2, bits, operation});
   152         tests.add(new Object[]{lowerBound1, upperBound1, lowerBound2, upperBound2, bits, operation});