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

Roland Westrelin roland at openjdk.java.net
Fri Dec 3 10:22:33 UTC 2021


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.

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

Depends on: https://git.openjdk.java.net/jdk/pull/6607

Commit messages:
 - whitespace
 - fix

Changes: https://git.openjdk.java.net/jdk/pull/6697/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=6697&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8277850
  Stats: 207 lines in 4 files changed: 206 ins; 0 del; 1 mod
  Patch: https://git.openjdk.java.net/jdk/pull/6697.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/6697/head:pull/6697

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


More information about the hotspot-compiler-dev mailing list