RFR: 8282365: Optimize divideUnsigned and remainderUnsigned for constants [v4]

Vladimir Kozlov kvn at openjdk.org
Tue Sep 27 20:05:26 UTC 2022


On Tue, 27 Sep 2022 19:10:26 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:

>> src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp line 5468:
>> 
>>> 5466:   // Fastpath for divisor < 0:
>>> 5467:   // quotient = (dividend & ~(dividend - divisor)) >>> (Integer.SIZE - 1)
>>> 5468:   // See Hacker's Delight (2nd ed), section 9.3 which is implemented in java.lang.Long.divideUnsigned()
>> 
>> Where is ideal implementation of this optimization (you changed `.ad` to handle only positive cases)?
>> I see you mixed positive and negative divisor values in JMH tests. Can you do separately?
>
> An ideal rule is added to transform the division if the divisor is known to be negative, I don't think a runtime branch is beneficial, and users of the method can always do it from Java if the data is expected to have a significant rate of negative divisor. WDYT?

I am fine with ideal transformation instead of runtime check in code. The problem is I can't find this new ideal transformation in your changes. I don't see check for **not constant** negative divisor.
I would leave **not constant devisor** case alone. It could be problematic to introduce control flow into ideal graph for these nodes.

-------------

PR: https://git.openjdk.org/jdk/pull/9947


More information about the hotspot-compiler-dev mailing list