# HG changeset patch # User Roland Schatz # Date 1435231028 -7200 # Node ID 660aa109e456862ddff045b6cdd369988c9c543f # Parent 1a769bce9a01a6ad9d54787e2e5e23cac95822b4 Simplify maxTripCountNode method. diff -r 1a769bce9a01 -r 660aa109e456 graal/com.oracle.graal.loop/src/com/oracle/graal/loop/CountedLoopInfo.java --- a/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/CountedLoopInfo.java Mon Jun 22 11:42:54 2015 +0200 +++ b/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/CountedLoopInfo.java Thu Jun 25 13:17:08 2015 +0200 @@ -56,26 +56,21 @@ StructuredGraph graph = iv.valueNode().graph(); Stamp stamp = iv.valueNode().stamp(); ValueNode range = sub(graph, end, iv.initNode()); - if (!iv.isConstantStride() || Math.abs(iv.constantStride()) != 1) { - ValueNode stride = iv.strideNode(); - if (!oneOff) { - if (iv.direction() == Direction.Up) { - stride = sub(graph, stride, ConstantNode.forIntegerStamp(stamp, 1, graph)); - } else { - assert iv.direction() == Direction.Down; - stride = add(graph, stride, ConstantNode.forIntegerStamp(stamp, 1, graph)); - } - } - range = add(graph, range, stride); - } else if (oneOff) { - if (iv.direction() == Direction.Up) { - range = add(graph, range, ConstantNode.forIntegerStamp(stamp, 1, graph)); - } else { - assert iv.direction() == Direction.Down; - range = sub(graph, range, ConstantNode.forIntegerStamp(stamp, 1, graph)); - } + + ValueNode oneDirection; + if (iv.direction() == Direction.Up) { + oneDirection = ConstantNode.forIntegerStamp(stamp, 1, graph); + } else { + assert iv.direction() == Direction.Down; + oneDirection = ConstantNode.forIntegerStamp(stamp, -1, graph); } - ValueNode div = divBefore(graph, loop.entryPoint(), range, iv.strideNode()); + if (oneOff) { + range = add(graph, range, oneDirection); + } + // round-away-from-zero divison: (range + stride -/+ 1) / stride + ValueNode denominator = add(graph, sub(graph, range, oneDirection), iv.strideNode()); + ValueNode div = divBefore(graph, loop.entryPoint(), denominator, iv.strideNode()); + if (assumePositive) { return div; }