src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/CountedLoopInfo.java
changeset 48861 47f19ff9903c
parent 48190 25cfedf27edc
child 49451 e06f9607f370
equal deleted inserted replaced
48860:5bce1b7e7800 48861:47f19ff9903c
    71     public ValueNode maxTripCountNode(boolean assumePositive) {
    71     public ValueNode maxTripCountNode(boolean assumePositive) {
    72         StructuredGraph graph = iv.valueNode().graph();
    72         StructuredGraph graph = iv.valueNode().graph();
    73         Stamp stamp = iv.valueNode().stamp(NodeView.DEFAULT);
    73         Stamp stamp = iv.valueNode().stamp(NodeView.DEFAULT);
    74         ValueNode range = sub(graph, end, iv.initNode());
    74         ValueNode range = sub(graph, end, iv.initNode());
    75 
    75 
       
    76         ValueNode max;
       
    77         ValueNode min;
    76         ValueNode oneDirection;
    78         ValueNode oneDirection;
    77         if (iv.direction() == Direction.Up) {
    79         if (iv.direction() == Direction.Up) {
    78             oneDirection = ConstantNode.forIntegerStamp(stamp, 1, graph);
    80             oneDirection = ConstantNode.forIntegerStamp(stamp, 1, graph);
       
    81             max = end;
       
    82             min = iv.initNode();
    79         } else {
    83         } else {
    80             assert iv.direction() == Direction.Down;
    84             assert iv.direction() == Direction.Down;
    81             oneDirection = ConstantNode.forIntegerStamp(stamp, -1, graph);
    85             oneDirection = ConstantNode.forIntegerStamp(stamp, -1, graph);
       
    86             max = iv.initNode();
       
    87             min = end;
    82         }
    88         }
    83         if (oneOff) {
    89         if (oneOff) {
    84             range = add(graph, range, oneDirection);
    90             range = add(graph, range, oneDirection);
    85         }
    91         }
    86         // round-away-from-zero divison: (range + stride -/+ 1) / stride
    92         // round-away-from-zero divison: (range + stride -/+ 1) / stride
    93 
    99 
    94         if (assumePositive) {
   100         if (assumePositive) {
    95             return div;
   101             return div;
    96         }
   102         }
    97         ConstantNode zero = ConstantNode.forIntegerStamp(stamp, 0, graph);
   103         ConstantNode zero = ConstantNode.forIntegerStamp(stamp, 0, graph);
    98         return graph.unique(new ConditionalNode(graph.unique(new IntegerLessThanNode(zero, div)), div, zero));
   104         return graph.unique(new ConditionalNode(graph.unique(new IntegerLessThanNode(max, min)), zero, div));
    99     }
   105     }
   100 
   106 
   101     /**
   107     /**
   102      * @return true if the loop has constant bounds and the trip count is representable as a
   108      * @return true if the loop has constant bounds and the trip count is representable as a
   103      *         positive integer.
   109      *         positive integer.