RFR: 8321308: AArch64: Fix matching predication for cbz/cbnz [v2]

Fei Gao fgao at openjdk.org
Thu Jun 6 14:35:29 UTC 2024


> For array length check like:
> 
>   if (a.length > 0) {
>     [Block 1]
>   } else {
>     [Block 2]
>   }
> 
> 
> Since `a.length` is unsigned, it's semantically equivalent to:
> 
>   if (a.length != 0) {
>     [Block 1]
>   } else {
>     [Block 2]
>   }
> 
> 
> On aarch64 port, we can do the conversion like above, during c2 compiler instruction matching, for certain unsigned integral comparisons.
> 
> For example,
> 
> cmpw  w11, #0 # unsigned
> bls   label   # unsigned
> [Block 1]
> 
> label:
> [Block 2]
> 
> 
> can be converted to:
> 
> cbz  w11, label
> [Block 1]
> 
> label:
> [Block 2]
> 
> 
> Currently, we have some matching rules to do the conversion [[1]](https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/aarch64/aarch64.ad#L16179). But the predicate here [[2]](https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/aarch64/aarch64.ad#L6140) matches wrong `BoolTest` masks, so these rules fail to convert. I guess it's a typo introduced in [JDK-8160006](https://bugs.openjdk.org/browse/JDK-8160006). The patch fixes it.

Fei Gao 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 three additional commits since the last revision:

 - Redefine the interface for cmpOpUEqNeLeGt
 - Merge branch 'master' into fg8321308
 - 8321308: AArch64: Fix matching predication for cbz/cbnz
   
   For array length check like:
   ```
     if (a.length > 0) {
       [Block 1]
     } else {
       [Block 2]
     }
   ```
   
   Since `a.length` is unsigned, it's semantically equivalent to:
   ```
     if (a.length != 0) {
       [Block 1]
     } else {
       [Block 2]
     }
   ```
   
   On aarch64 port, we can do the conversion like above, during c2
   compiler instruction matching, for certain unsigned integral
   comparisons.
   
   For example,
   ```
   cmpw  w11, #0 # unsigned
   bls   label   # unsigned
   [Block 1]
   
   label:
   [Block 2]
   ```
   
   can be converted to:
   ```
   cbz  w11, label
   [Block 1]
   
   label:
   [Block 2]
   ```
   
   Currently, we have some matching rules to do the conversion[1].
   But the predicate here[2] matches wrong `BoolTest` masks,
   so these rules fail to convert. I guess it's a typo introduced
   in JDK-8160006. The patch fixes it.
   
   [1] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/aarch64/aarch64.ad#L16179
   [2] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/aarch64/aarch64.ad#L6140

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/16989/files
  - new: https://git.openjdk.org/jdk/pull/16989/files/066134a2..c49553b9

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=16989&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=16989&range=00-01

  Stats: 871263 lines in 11702 files changed: 263300 ins; 226217 del; 381746 mod
  Patch: https://git.openjdk.org/jdk/pull/16989.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/16989/head:pull/16989

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


More information about the hotspot-compiler-dev mailing list