RFR: 8273021: C2: Improve Add and Xor ideal optimizations [v5]

Yi Yang yyang at openjdk.java.net
Fri Sep 10 07:41:36 UTC 2021


> Greetings. This patch adds the following identical equations for Add and Xor node, respectively, which probably drives further optimizations.
> 
> 
> ~(x-1) => -x
> ~x + 1 => -x
> 
> 
> 
> Verified by generated opto assembly, maybe an IR verification test can be added later.
> 
> Compiled method (c2)      71    1             compiler.c2.TestAddXorIdeal::test1 (6 bytes)
>   0x00007f9e11514800:   sub    $0x18,%rsp
>   0x00007f9e11514807:   mov    %rbp,0x10(%rsp)              ;*synchronization entry
>                                                             ; - compiler.c2.TestAddXorIdeal::test1 at -1 (line 39)
>   0x00007f9e1151480c:   mov    %esi,%eax
>   0x00007f9e1151480e:   neg    %eax                         ;*iadd {reexecute=0 rethrow=0 return_oop=0}
>                                                             ; - compiler.c2.TestAddXorIdeal::test1 at 4 (line 39)
>   0x00007f9e11514810:   add    $0x10,%rsp
>   0x00007f9e11514814:   pop    %rbp
>   0x00007f9e11514815:   cmp    0x338(%r15),%rsp             ;   {poll_return}
>   0x00007f9e1151481c:   ja     0x00007f9e11514823
>   0x00007f9e11514822:   retq   
> 
> Compiled method (c2)      73    2             compiler.c2.TestAddXorIdeal::test2 (6 bytes)
>   0x00007f9e11512480:   sub    $0x18,%rsp
>   0x00007f9e11512487:   mov    %rbp,0x10(%rsp)              ;*synchronization entry
>                                                             ; - compiler.c2.TestAddXorIdeal::test2 at -1 (line 43)
>   0x00007f9e1151248c:   mov    %esi,%eax
>   0x00007f9e1151248e:   neg    %eax                         ;*ixor {reexecute=0 rethrow=0 return_oop=0}
>                                                             ; - compiler.c2.TestAddXorIdeal::test2 at 4 (line 43)
>   0x00007f9e11512490:   add    $0x10,%rsp
>   0x00007f9e11512494:   pop    %rbp
>   0x00007f9e11512495:   cmp    0x338(%r15),%rsp             ;   {poll_return}
>   0x00007f9e1151249c:   ja     0x00007f9e115124a3
>   0x00007f9e115124a2:   retq 
> 
> Compiled method (c2)      72    3             compiler.c2.TestAddXorIdeal::test3 (8 bytes)
>   0x00007f9e11514b00:   sub    $0x18,%rsp
>   0x00007f9e11514b07:   mov    %rbp,0x10(%rsp)              ;*synchronization entry
>                                                             ; - compiler.c2.TestAddXorIdeal::test3 at -1 (line 47)
>   0x00007f9e11514b0c:   mov    %rsi,%rax
>   0x00007f9e11514b0f:   neg    %rax                         ;*ladd {reexecute=0 rethrow=0 return_oop=0}
>                                                             ; - compiler.c2.TestAddXorIdeal::test3 at 6 (line 47)
>   0x00007f9e11514b12:   add    $0x10,%rsp
>   0x00007f9e11514b16:   pop    %rbp
>   0x00007f9e11514b17:   cmp    0x338(%r15),%rsp             ;   {poll_return}
>   0x00007f9e11514b1e:   ja     0x00007f9e11514b25
>   0x00007f9e11514b24:   retq  
> 
> Compiled method (c2)      72    4             compiler.c2.TestAddXorIdeal::test4 (8 bytes)
>   0x00007f9e11514500:   sub    $0x18,%rsp
>   0x00007f9e11514507:   mov    %rbp,0x10(%rsp)              ;*synchronization entry
>                                                             ; - compiler.c2.TestAddXorIdeal::test4 at -1 (line 51)
>   0x00007f9e1151450c:   mov    %rsi,%rax
>   0x00007f9e1151450f:   neg    %rax                         ;*lxor {reexecute=0 rethrow=0 return_oop=0}
>                                                             ; - compiler.c2.TestAddXorIdeal::test4 at 6 (line 51)
>   0x00007f9e11514512:   add    $0x10,%rsp
>   0x00007f9e11514516:   pop    %rbp
>   0x00007f9e11514517:   cmp    0x338(%r15),%rsp             ;   {poll_return}
>   0x00007f9e1151451e:   ja     0x00007f9e11514525
>   0x00007f9e11514524:   retq  
> 
> Compiled method (c2)      72    5             compiler.c2.TestAddXorIdeal::test5 (6 bytes)
>   0x00007f9e11518500:   sub    $0x18,%rsp
>   0x00007f9e11518507:   mov    %rbp,0x10(%rsp)              ;*synchronization entry
>                                                             ; - compiler.c2.TestAddXorIdeal::test5 at -1 (line 55)
>   0x00007f9e1151850c:   mov    %esi,%eax
>   0x00007f9e1151850e:   neg    %eax                         ;*iadd {reexecute=0 rethrow=0 return_oop=0}
>                                                             ; - compiler.c2.TestAddXorIdeal::test5 at 4 (line 55)
>   0x00007f9e11518510:   add    $0x10,%rsp
>   0x00007f9e11518514:   pop    %rbp
>   0x00007f9e11518515:   cmp    0x338(%r15),%rsp             ;   {poll_return}
>   0x00007f9e1151851c:   ja     0x00007f9e11518523
>   0x00007f9e11518522:   retq  
> 
> Compiled method (c2)      74    6             compiler.c2.TestAddXorIdeal::test6 (6 bytes)
>   0x00007f9e11512180:   sub    $0x18,%rsp
>   0x00007f9e11512187:   mov    %rbp,0x10(%rsp)              ;*synchronization entry
>                                                             ; - compiler.c2.TestAddXorIdeal::test6 at -1 (line 59)
>   0x00007f9e1151218c:   mov    %esi,%eax
>   0x00007f9e1151218e:   neg    %eax                         ;*ixor {reexecute=0 rethrow=0 return_oop=0}
>                                                             ; - compiler.c2.TestAddXorIdeal::test6 at 4 (line 59)
>   0x00007f9e11512190:   add    $0x10,%rsp
>   0x00007f9e11512194:   pop    %rbp
>   0x00007f9e11512195:   cmp    0x338(%r15),%rsp             ;   {poll_return}
>   0x00007f9e1151219c:   ja     0x00007f9e115121a3
>   0x00007f9e115121a2:   retq  
> 
> Compiled method (c2)      74    7             compiler.c2.TestAddXorIdeal::test7 (8 bytes)
>   0x00007f9e11511e80:   sub    $0x18,%rsp
>   0x00007f9e11511e87:   mov    %rbp,0x10(%rsp)              ;*synchronization entry
>                                                             ; - compiler.c2.TestAddXorIdeal::test7 at -1 (line 63)
>   0x00007f9e11511e8c:   mov    %rsi,%rax
>   0x00007f9e11511e8f:   neg    %rax                         ;*ladd {reexecute=0 rethrow=0 return_oop=0}
>                                                             ; - compiler.c2.TestAddXorIdeal::test7 at 6 (line 63)
>   0x00007f9e11511e92:   add    $0x10,%rsp
>   0x00007f9e11511e96:   pop    %rbp
>   0x00007f9e11511e97:   cmp    0x338(%r15),%rsp             ;   {poll_return}
>   0x00007f9e11511e9e:   ja     0x00007f9e11511ea5
>   0x00007f9e11511ea4:   retq 
> 
> 
> Compiled method (c2)      73    8             compiler.c2.TestAddXorIdeal::test8 (10 bytes)
>   0x00007f9e11512780:   sub    $0x18,%rsp
>   0x00007f9e11512787:   mov    %rbp,0x10(%rsp)              ;*synchronization entry
>                                                             ; - compiler.c2.TestAddXorIdeal::test8 at -1 (line 67)
>   0x00007f9e1151278c:   mov    %rsi,%rax
>   0x00007f9e1151278f:   neg    %rax                         ;*lxor {reexecute=0 rethrow=0 return_oop=0}
>                                                             ; - compiler.c2.TestAddXorIdeal::test8 at 8 (line 67)
>   0x00007f9e11512792:   add    $0x10,%rsp
>   0x00007f9e11512796:   pop    %rbp
>   0x00007f9e11512797:   cmp    0x338(%r15),%rsp             ;   {poll_return}
>   0x00007f9e1151279e:   ja     0x00007f9e115127a5
>   0x00007f9e115127a4:   retq

Yi Yang has updated the pull request incrementally with one additional commit since the last revision:

  change

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/5266/files
  - new: https://git.openjdk.java.net/jdk/pull/5266/files/aee3a8b0..cceb0613

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=5266&range=04
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=5266&range=03-04

  Stats: 19 lines in 1 file changed: 0 ins; 8 del; 11 mod
  Patch: https://git.openjdk.java.net/jdk/pull/5266.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/5266/head:pull/5266

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


More information about the hotspot-compiler-dev mailing list