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

Joshua Cao duke at openjdk.org
Mon Apr 8 18:42:43 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 incrementally with one additional commit since the last revision:

  Update src/hotspot/share/opto/loopTransform.cpp
  
  formatting
  
  Co-authored-by: Christian Hagedorn <christian.hagedorn at oracle.com>

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/17375/files
  - new: https://git.openjdk.org/jdk/pull/17375/files/1b27aae4..3bcab3bb

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

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 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