RFR: 8277850: C2: optimize mask checks in counted loops

Vladimir Kozlov kvn at openjdk.java.net
Sat Dec 4 00:08:15 UTC 2021


On Fri, 3 Dec 2021 10:04:58 GMT, Roland Westrelin <roland at openjdk.org> wrote:

> This is another fix that addresses a performance issue with panama and that was brought up by Maurizio. The pattern to optimize is:
> if ((base + (offset << 2)) & 3) != 0) {
> }
> 
> where base is loop independent but offset depends on a loop variable. This can be transformed to:
> 
> if ((base & 3) != 0) {
> 
> That check becomes loop independent and be optimized by loop predication (or I suppose loop unswitching but that wasn't the case of the micro benchmark I worked on).
> 
> This change also optimizes the pattern:
> 
> (offset << 2) & 3
> 
> to return 0.

@rwestrel  there is issue with build on Windows:

d:\a\jdk\jdk\jdk\src\hotspot\share\opto\mulnode.cpp(1746): error C2220: the following warning is treated as an error
20
d:\a\jdk\jdk\jdk\src\hotspot\share\opto\mulnode.cpp(1746): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
21

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

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


More information about the hotspot-compiler-dev mailing list