Suboptimal code generation in C2?

Vitaly Davidovich vitalyd at
Wed Sep 23 19:04:23 UTC 2015

Thanks Aleksey.

The cmov is probably a non-issue here since both dependencies are in
registers.  The arithmetic dance, jumps, and register allocation seems off
though.  For instance, esi is cleared with xor then it jumps to code that
adds edx to esi, then it moves esi into eax - this could be replaced with
moving edx into eax.

sent from my phone


On 09/23/2015 08:49 PM, Vitaly Davidovich wrote:
> Consider this simple method:
>     private static int test(final int ops, int start) {
>         for (int i = 0; i < ops; ++i) {
>             start++;
>         }
>         return start;
>     }

> test(int, int):
> leal(%rsi,%rdi), %edx
> movl%esi, %eax
> testl%edi, %edi
> cmovg%edx, %eax
> ret
> Any ideas on why C2 doesn't generate roughly the same thing? Clang 3.7
> and ICC 13.0.1 are almost the same as the GCC output above.

Yup, could be better:

I am not entirely sure conditional move is better than a branch in this
particular case, since $ops is probably always non-negative in practice.
HotSpot generates a branch there, which is good. The arithmetic dance is
indeed not very clean -- I'd speculate that's a leftover from loop peeling.


sent from my phone
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the hotspot-compiler-dev mailing list