RFR(M): 8223051: support loops with long (64b) trip counts

John Rose john.r.rose at oracle.com
Fri Jun 5 22:56:48 UTC 2020


On Jun 5, 2020, at 10:54 AM, Vladimir Kozlov <vladimir.kozlov at oracle.com> wrote:
> 
> In original RFR, Roland, you showed that loop will be transformed into:
> 
> for (long l = long_start; l < long_stop; ) {
>  int int_stride = (int)long_stride;
>  int int_stop = MIN(long_stop - l, max_jint - int_stride);
>  l += int_stop;
>  for (int i = 0; i < int_stop; i += int_stride) {
>  }
> }

That formula is out of date; there is a new one in the source code
which is more accurate (see loopnode.cpp):

If the loop has the shape of a counted loop but with a long
induction variable, transform the loop in a loop nest: an inner
loop that iterates for at most max int iterations with an integer
induction variable and an outer loop that iterates over the full
range of long values from the initial loop in (at most) max int
steps. That is:
L: for (long phi = init; phi < limit; phi += stride) {
   // phi := Phi(L, init, phi + stride)
   … use phi and (phi + stride) …
}

==transform=>

const long inner_iters_limit = INT_MAX - stride;
assert(stride <= inner_iters_limit);  // else deopt
assert(limit + stride <= LONG_MAX);
L1: for (long phi1 = init; phi1 < limit; phi1 += stride) {
   // phi1 := Phi(L1, init, phi1 + stride)
   long inner_iters_max = MAX(0, limit + stride - phi1);
   long inner_iters_actual = MIN(inner_iters_max, inner_iters_limit);
   L2: for (int phi2 = 0; phi2 < inner_iters_actual; phi2 += stride) {
      … use (phi1 + phi2) and (phi1 + phi2 + stride) …
   }
}

> 
> My question is about 'l += int_stop'. Do you optimize only loops which does not have any references to 'l' inside loop?
> Will you process expressions like (l + i) in inner loops?


So to answer your questions, occurrences of the long tripcount
“phi” are replaced by a sum of a long (inner loop invariant) and
an int (inner trip count), as “phi1+phi2”.

The expression (l + i) should transform also, since the “l” part
is just the original “phi”.

— John


More information about the hotspot-compiler-dev mailing list