RFR: 8323220: Reassociate loop invariants involved in Cmps and Add/Subs [v10]

Joshua Cao duke at openjdk.org
Fri Feb 16 00:58:13 UTC 2024


> // inv1 == (x + inv2) => ( inv1 - inv2 ) == x
> // inv1 == (x - inv2) => ( inv1 + inv2 ) == x
> // inv1 == (inv2 - x) => (-inv1 + inv2 ) == x
> 
> 
> For example,
> 
> 
> fn(inv1, inv2)
>   while(...)
>       x = foobar()
>       if inv1 == x + inv2
>            blackhole()
> 
> 
> We can transform this into
> 
> 
> fn(inv1, inv2)
>   t = inv1 - inv2
>   while(...)
>       x = foobar()
>       if t == x
>            blackhole()
> 
> 
> Here is an example: https://github.com/openjdk/jdk/blob/b78896b9aafcb15f453eaed6e154a5461581407b/src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java#L910. LHS `1` and RHS `pos` are both loop invariant
> 
> Passes tier1 locally on Linux machine. Passes GHA on my fork.

Joshua Cao 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 12 additional commits since the last revision:

 - Update test to utilize @setup method for arguments
 - Merge branch 'master' into licm
 - Add correctness test for some random tests with random inputs
 - Add some correctness tests where we do reassociate
 - Remove unused TestInfo parameter. Have some tests exit mid-loop.
 - Merge branch 'master' into licm
 - Small fixes and add check methods for tests
 - reassociate_add_sub -> reassociate_add_sub_cmp
 - Formatting and fix typo
 - Assert for n2. Variables for n1/n2 opcode. More concise comments.
   Overflow/random tests
 - ... and 2 more: https://git.openjdk.org/jdk/compare/ce9fea56...ad073ef2

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/17375/files
  - new: https://git.openjdk.org/jdk/pull/17375/files/b29c557c..ad073ef2

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=17375&range=09
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=17375&range=08-09

  Stats: 27649 lines in 976 files changed: 12267 ins; 9792 del; 5590 mod
  Patch: https://git.openjdk.org/jdk/pull/17375.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/17375/head:pull/17375

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


More information about the hotspot-compiler-dev mailing list