RFR: 8270366: C2: Add associative rule to add/sub node

Zhengyu Gu zgu at openjdk.java.net
Wed Jul 14 14:15:09 UTC 2021


On Tue, 13 Jul 2021 22:47:11 GMT, Dean Long <dlong at openjdk.org> wrote:

> Can this rule cause the JIT to compute different results than the interpreter if there is integer overflow? Does the spec allow that?

Based on [https://www.agner.org/optimize/optimizing_cpp.pdf](Optimizing software in C++), this optimization is implemented in all 4 compilers (GNU, Clang, Microsoft and Intel) author investigated.

For example:

long mask(long a, long b, long c) {
    return a*b + a*c ;
}

GNU/Clang:


 lea    rax,[rdx+rsi*1]
 imul   rax,rdi

MSVC:   


lea     eax, DWORD PTR [rdx+r8]
imul    eax, ecx

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

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


More information about the hotspot-compiler-dev mailing list