Possible compiler bug: continue is skipped after or-condition

Andrew Dinn adinn at redhat.com
Thu Feb 20 10:03:21 UTC 2020

On 19/02/2020 19:45, B. Blaser wrote:
> Some JVM expert (like Andrew) might confirm, but I believe the C2
> generated code (x86_64) would still be optimal with a "continue"
> elision reversion as here under. As we can see, both bci:23 and bci:33
> would go directly to B10 which either starts a new iteration at B6 or
> exits through B5.

The problem with this experiment is that it misses an important aspect
of how compiler branch optimization works. The organization of branching
structure in the JITted code is heavily conditioned by branch profile
information. Branch conditions may be (and often are) flipped to place a
hot path in the direct drop-through line, moving the cold path out of line.

Note that such re-location of code paths does not just imply re-ordering
them between the loop start and back edge. A branch to a cold path may
well jump out beyond the loop back edge terminating with a jump back
into the middle of the loop body. The idea is to improve instruction
cache locality by ensuring that as much hot code as possible is
contained in a tight, contiguous segment. This usually works very
efficiently with standard hw branch predictors + cache prefetchers.

So, I am afraid the code your test has generated is not necessarily
going to reflect the code layout that would happen in production code
executing a method with a similar loop + loop exit structure. The branch
layout might even vary from one run to the next (or even from one C2 JIT
compile to a C2 JIT recompile if a deopt happens). That said, what I
think the test does show is that the compiler does know how to unravel
the sort of indirect jump this reversion might introduce.

> Should I file a JBS issue to track this potential fix or would we
> prefer investigating a much more holistic refactoring in this area?
Well, I'd follow Maurizio's advice and add this to a slate for a later
reckoning of highest priorities against most effective remedies.


Andrew Dinn
Senior Principal Software Engineer
Red Hat UK Ltd
Registered in England and Wales under Company Registration No. 03798903
Directors: Michael Cunningham, Michael ("Mike") O'Neill

More information about the compiler-dev mailing list