Re: can graal unroll loop with more blocks

Kuai Wei at
Tue May 14 02:55:15 UTC 2019

Hi Gilles,

   Thanks for your help. My understanding is if loop has single exit, it's an unroll candidate. I will investigate if we can apply the new rule. Is there other check we need care?

Best Regards,
Kuai Wei

From:Gilles Duboscq <gilles.m.duboscq at>
Send Time:2019年5月13日(星期一) 20:37
To:graal-dev <graal-dev at>
Subject:Re: can graal unroll loop with more blocks

Hi Kuai,

You can not safely change that limit there: this is not a heuristic but a necessary check because the code behind this transformation will produce incorrect results with more blocks.

It would be not be very hard to change this limit to be about the loop having a single loop exit. But with multiple loop exits it would be a much larger change.


On 13/05/2019 13:57, Kuai Wei wrote:
> Hello,
>    Recently I checked loop unroll optimization in Graal compiler. I found it has a strict check to limit unroll loop with 1 or 2 blocks.
> In
> public static boolean isUnrollableLoop(LoopEx loop) {
>    ...
>    if (loopBegin.isMainLoop() || loopBegin.isSimpleLoop()) {
>              // Flow-less loops to partial unroll for now. 3 blocks corresponds to an if that either
>              // exits or continues the loop. There might be fixed and floating work within the loop
>              // as well.
>              if (loop.loop().getBlocks().size() < 3) {
>                  return true;
>              }
>              condition.getDebug().log(DebugContext.VERBOSE_LEVEL, "isUnrollableLoop %s too large to unroll %s ", loopBegin, loop.loop().getBlocks().size());
>     }
> I'm wondering why Graal has this limit. It will block many loops to be unrolled. Could we increase the block size here?
> Thanks,
> Kuai Wei

More information about the graal-dev mailing list