Integrated: 8273021: C2: Improve Add and Xor ideal optimizations
Yi Yang
yyang at openjdk.java.net
Mon Sep 13 02:13:56 UTC 2021
On Thu, 26 Aug 2021 09:19:41 GMT, Yi Yang <yyang at openjdk.org> wrote:
> 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
This pull request has now been integrated.
Changeset: a73c06de
Author: Yi Yang <yyang at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/a73c06de2ac47033503189140c0f8ee61fcbceae
Stats: 137 lines in 3 files changed: 136 ins; 0 del; 1 mod
8273021: C2: Improve Add and Xor ideal optimizations
Co-authored-by: yulei <lei.yul at alibaba-inc.com>
Reviewed-by: thartmann, kvn
-------------
PR: https://git.openjdk.java.net/jdk/pull/5266
More information about the hotspot-compiler-dev
mailing list