RFR: 8332268: C2: Add missing optimizations for UDivI/L and UModI/L and unify the shared logic with the signed nodes

theoweidmannoracle duke at openjdk.org
Mon Nov 25 09:16:17 UTC 2024


On Mon, 25 Nov 2024 09:04:09 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> This PR introduces
>> - several new optimizations to unsigned division and modulo
>>    - x % 1, x % x, x % 2^k
>>    - x / 1, x / x, x / 2^k 
>>    - does not implement the Granlund and Montgomery algorithm, which has been implemented for signed modulo division in the past. It is unclear if a lot is to be gained by implementing this.
>> - tests to test existing optimizations for signed division and modulo 
>>    - does not test the Granlund and Montgomery algorithm directly
>
> src/hotspot/share/opto/divnode.cpp line 518:
> 
>> 516: 
>> 517:   if (is_power_of_2(l)) {
>> 518:     return make_urshift<TypeClass>(div->in(1), phase->intcon(log2i_graceful(l)));
> 
> Are we testing optimizations like these with random constants somewhere, and comparing it to the interpreter results?

https://github.com/openjdk/jdk/pull/22061/files#diff-48b0b8da547a3fe6aae9ea3ef20b4d708e47f2332ff6884478336f39d9eb9459R82 and https://github.com/openjdk/jdk/pull/22061/files#diff-24679e6505fe23e8a3ba73decaaf97896899c0a10956c437b8721fca33706ee2R82 should cover this I think. The containing method is marked with @DontCompile.

> test/hotspot/jtreg/compiler/c2/irTests/ModINodeIdealizationTests.java line 2:
> 
>> 1: /*
>> 2:  * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
> 
> Suggestion:
> 
>  * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
> 
> Check the others too. I don't think a new file requires old dates ;)

The basic structure is based of the existing tests (I think mostly DivINodeIdealizationTests) so I was thinking this is a derivative work.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22061#discussion_r1856195539
PR Review Comment: https://git.openjdk.org/jdk/pull/22061#discussion_r1856191718


More information about the hotspot-compiler-dev mailing list