RFR: 8273454: C2: Transform (-a)*(-b) into a*b [v2]

Tobias Hartmann thartmann at openjdk.java.net
Thu Sep 9 07:34:04 UTC 2021


On Wed, 8 Sep 2021 02:09:38 GMT, Zhengyu Gu <zgu at openjdk.org> wrote:

>> The transformation reduce instructions in generated code.
>> 
>> ### x86_64:
>> 
>> Before:
>> ```  
>>   0x00007fb92c78b3ac:   neg    %esi
>>   0x00007fb92c78b3ae:   neg    %edx
>>   0x00007fb92c78b3b0:   mov    %esi,%eax
>>   0x00007fb92c78b3b2:   imul   %edx,%eax                    ;*imul {reexecute=0 rethrow=0 return_oop=0}
>>                                                             ; - TestSub::runSub at 4 (line 9)
>> 
>> After:
>> 
>>                                                            ; - TestSub::runSub at -1 (line 9)
>>   0x00007fc8c05b74ac:   mov    %esi,%eax
>>   0x00007fc8c05b74ae:   imul   %edx,%eax                    ;*imul {reexecute=0 rethrow=0 return_oop=0}
>>                                                             ; - TestSub::runSub at 4 (line 9)
>> 
>> 
>> 
>> ### AArch64:
>> Before:
>> 
>>  0x0000ffff814b4a70:   neg     w11, w1
>>  0x0000ffff814b4a74:   mneg    w0, w2, w11                 ;*imul {reexecute=0 rethrow=0 return_oop=0}
>>                                                             ; - TestSub::runSub at 4 (line 9)
>> 
>> 
>> After:
>> 
>>  0x0000ffff794a67f0:   mul     w0, w1, w2                  ;*imul {reexecute=0 rethrow=0 return_oop=0}
>>                                                             ; - TestSub::runSub at 4 (line 9)
>
> Zhengyu Gu has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix test

Changes requested by thartmann (Reviewer).

test/hotspot/jtreg/compiler/integerArithmetic/TestNegMultiply.java line 26:

> 24: /**
> 25:  * @test
> 26:  * @bug 8270366

The bug number is incorrect.

test/hotspot/jtreg/compiler/integerArithmetic/TestNegMultiply.java line 52:

> 50:             int result = intTest(intParams[index][0], intParams[index][1]);
> 51:             for (int i = 0; i < 20_000; i++) {
> 52:                 if (result != intTest(intParams[index][0], intParams[index][1])) {

After some warmup iterations, `intTest` will be C2 compiled and you are then comparing outputs of the same compiled method. I.e., if there's a bug in the C2 optimization, the test might not catch it. What you should do instead, is to compare the output of the C2 compiled method to the expected value (which is `a * b` in this case).

You should also prevent inlining of `intTest`.

The test you added with JDK-8270366 has the same problem.

test/hotspot/jtreg/compiler/integerArithmetic/TestNegMultiply.java line 59:

> 57:     }
> 58: 
> 59:     private static final long[][] longParams = {

Similar to https://git.openjdk.java.net/jdk/pull/5266, I would prefer random values for better coverage.

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

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


More information about the hotspot-compiler-dev mailing list