Conditional moves vs. branching in unrolled loops

Paul Sandoz paul.sandoz at
Wed Jan 6 14:34:29 UTC 2016

> On 6 Jan 2016, at 13:38, Vitaly Davidovich <vitalyd at> wrote:
> Perhaps for conditional moves data dependency chains are more costly?
> cmov carries a dependency on both inputs, making it more likely to stall when at least one isn't available whereas the branch still allows cpu to continue with speculative execution.  In a tight loop with a memory access as one input to cmov, the memory op has to retire before cmov can proceed; using cmov when both inputs are already ready (e.g. values in registers) is pretty harmless though and avoids a branch entirely.  cmov also has larger encoding than a branch.

Ok. The generated code for an unrolled loop firsts load array elements into registers before performing the cmovs.

> As the original jira on this issue states, cmov should only be used when the branch is profiled to be unpredictable.  I'm not sure why loops with a max/min accumulator need to be called out separately in this regard - wouldn't the branch profile dictate this anyway?

Yes, that was me not understanding the underlying branch profiling mechanisms.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <>

More information about the hotspot-compiler-dev mailing list