RFR: 8346664: C2: Optimize mask check with constant offset [v16]

Matthias Ernst duke at openjdk.org
Sun Feb 2 18:31:54 UTC 2025


> Fixes [JDK-8346664](https://bugs.openjdk.org/browse/JDK-8346664): extends the optimization of masked sums introduced in #6697 to cover constant values, which currently break the optimization.
> 
> Such constant values arise in an expression of the following form, for example from `MemorySegmentImpl#isAlignedForElement`:
> 
> 
> (base + (index + 1) << 8) & 255
> => MulNode
> (base + (index << 8 + 256)) & 255
> => AddNode
> ((base + index << 8) + 256) & 255
> 
> 
> Currently, `256` is not being recognized as a shifted value. This PR enables further reduction:
> 
> 
> ((base + index << 8) + 256) & 255
> => MulNode (this PR)
> (base + index << 8) & 255
> => MulNode (PR #6697)
> base & 255 (loop invariant)
> 
> 
> Implementation notes:
> * I verified that the originating issue "scaled varhandle indexed with i+1"  (https://mail.openjdk.org/pipermail/panama-dev/2024-December/020835.html) is resolved with this PR.
> * ~in order to stay with the flow of the current implementation, I refrained from solving general (const & mask)==0 cases, but only those where const == _ << shift.~
> * ~I modified existing test cases adding/subtracting from the index var (which would fail with current C2). Let me know if would like to see separate cases for these.~

Matthias Ernst has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 32 additional commits since the last revision:

 - Merge branch 'openjdk:master' into mernst/JDK-8346664
 - dropped bug ref.
 - indent
 - consistently label failing cases due to Align requirements.
 - Apply suggestions from code review
   
   Co-authored-by: Emanuel Peter <emanuel.peter at oracle.com>
 - disable `|` . comments.
 - "should never vectorize" only holds for long[] input.
 - completely disable IR rule
 - You can have two @IR rules with different applyIfs.
 - expect vectorization of i|7 instead of i&7
   i&7 variant expect "= 0".
 - ... and 22 more: https://git.openjdk.org/jdk/compare/52a5997d...98da0e0a

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/22856/files
  - new: https://git.openjdk.org/jdk/pull/22856/files/0e9de51d..98da0e0a

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=22856&range=15
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=22856&range=14-15

  Stats: 17118 lines in 260 files changed: 7406 ins; 6237 del; 3475 mod
  Patch: https://git.openjdk.org/jdk/pull/22856.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/22856/head:pull/22856

PR: https://git.openjdk.org/jdk/pull/22856


More information about the hotspot-compiler-dev mailing list