File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
compiler/src/jdk.graal.compiler/src/jdk/graal/compiler Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -696,7 +696,7 @@ public boolean ivCanNeverOverflow(InductionVariable iv) {
696
696
if (iv .isConstantInit () && isConstantMaxTripCount () && iv .isConstantStride ()) {
697
697
try {
698
698
final int bits = IntegerStamp .getBits (iv .valueNode ().stamp (NodeView .DEFAULT ));
699
- long tripCountMinus1 = LoopUtility .subtractExact (bits , maxTripCountNode (). asJavaConstant (). asLong ( ), 1 );
699
+ long tripCountMinus1 = LoopUtility .subtractExact (bits , LoopUtility . tripCountSignedExact ( this ), 1 );
700
700
long stripTimesTripCount = LoopUtility .multiplyExact (bits , iv .constantStride (), tripCountMinus1 );
701
701
@ SuppressWarnings ("unused" )
702
702
long extremum = LoopUtility .addExact (bits , stripTimesTripCount , iv .initNode ().asJavaConstant ().asLong ());
Original file line number Diff line number Diff line change 53
53
import jdk .graal .compiler .nodes .cfg .HIRBlock ;
54
54
import jdk .graal .compiler .nodes .extended .OpaqueValueNode ;
55
55
import jdk .graal .compiler .nodes .loop .BasicInductionVariable ;
56
+ import jdk .graal .compiler .nodes .loop .CountedLoopInfo ;
56
57
import jdk .graal .compiler .nodes .loop .InductionVariable ;
57
58
import jdk .graal .compiler .nodes .loop .Loop ;
58
59
import jdk .graal .compiler .nodes .loop .LoopsData ;
61
62
62
63
public class LoopUtility {
63
64
65
+ public static long tripCountSignedExact (CountedLoopInfo loop ) {
66
+ ValueNode maxTripCountNode = loop .maxTripCountNode ();
67
+ final long maxTripCountAsSigned = maxTripCountNode .asJavaConstant ().asLong ();
68
+ if (maxTripCountAsSigned < 0 ) {
69
+ throw new ArithmeticException ("Unsigned value " + maxTripCountAsSigned + " overflows signed range" );
70
+ }
71
+ return maxTripCountAsSigned ;
72
+ }
73
+
64
74
public static long addExact (int bits , long a , long b ) {
65
75
if (bits == 8 ) {
66
76
byte ba = NumUtil .safeToByteAE (a );
You can’t perform that action at this time.
0 commit comments