RFR: 8276673: Optimize abs operations in C2 compiler [v6]

Fei Gao fgao at openjdk.java.net
Fri Jan 14 06:46:26 UTC 2022


On Mon, 20 Dec 2021 09:40:39 GMT, Jie Fu <jiefu at openjdk.org> wrote:

>> Fei Gao has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Use uabs() to calculate the absolute value of constant
>>   
>>   Change-Id: Ie6f37ab159fb7092e1443b9af8d620562a45ae47
>
>> > But can you show us an example with more detailed analysis which pattern is applied in the test? Thanks.
>> 
>> Hi, @DamonFool
>> 
>> For example, `jdk/incubator/vector/Float512VectorTests.java` calls `java.lang.FdLibm$Hypot::compute`. You can check math classes in `Fdlibm.java`, like `Hypot` or a common one `Pow`, which calls `Math.abs()`. After inline and many optimizations, such as constant propagation, the input value of `Math.abs()` is probably constant or `(0-x)`. We can optimize it using this patch.
>> 
>> I learnt the optimization technique from the patch of my colleague, [#2776 (comment)](https://github.com/openjdk/jdk/pull/2776#issuecomment-789756226) The similar question was answered by Tobias in the conversation, and you can refer to it.
>> 
>> Thanks.
> 
> Very good!
> You had proved that these patterns do exist in C2's opt passes, so this patch makes sense to me.
> Thanks.

Thanks for your review, @DamonFool @TobiHartmann . I fixed all your points mentioned above.

> test/hotspot/jtreg/compiler/c2/TestAbs.java line 39:
> 
>> 37: 
>> 38: public class TestAbs {
>> 39:     private static int SIZE = 500;
> 
> Not used?

Done. Thanks.

> test/hotspot/jtreg/compiler/c2/TestAbs.java line 114:
> 
>> 112: 
>> 113:         // Test abs(constant) optimization for float
>> 114:         Asserts.assertEquals(Float.NaN, Math.abs(Float.NaN));
> 
> I would suggest something like:
> 
> assertTrue(Float.isNaN(Math.abs(Float.NaN)))

Done. Thanks.

> test/hotspot/jtreg/compiler/c2/TestAbs.java line 136:
> 
>> 134:     }
>> 135: 
>> 136:     private static void testAbsTransformInt(int[] a) {
> 
> If you want to verify C2's transformation, probably we should use C2's IR test framework.

Done. Thanks.

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

PR: https://git.openjdk.java.net/jdk/pull/6755


More information about the hotspot-compiler-dev mailing list