Conditional moves vs. branching in unrolled loops
john.r.rose at oracle.com
Wed Jan 6 01:05:56 UTC 2016
Darn, this works against the "say what you mean" story I told for checkIndex.
The bug here is very very special but is hit commonly so needs fixing. The special part is that accumulating Math.max values over a long loop almost *always* creates a series of predictable branches, which means cmov will lose on many CPUs places. (Exercise: Try to construct a long series of values for which each value is the largest so far, randomly, with 50% probability. This will not be a series found often in nature.)
We need to explicitly detect accumulations on cmov ops in long loops, and convert them to branches.
Also, we should continue to recommend using intrinsics instead of random logic.
Fun fact: Using your own branch logic makes the JVM manage a branch profile just for you, which can mean performance. Intrinsics, if they have internal branch logic, have polluted profiles. We need better call-site profiles and/or split profiles to overcome this.
> On Jan 5, 2016, at 4:47 AM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
>> On 5 Jan 2016, at 13:00, Vitaly Davidovich <vitalyd at gmail.com> wrote:
>> This is a known issue: https://bugs.openjdk.java.net/browse/JDK-8039104
> Many thanks, i closed JDK-8146071 as a dup of JDK-8039104.
More information about the hotspot-compiler-dev