RFR: 8323220: Reassociate loop invariants involved in Cmps and Add/Subs
Joshua Cao
duke at openjdk.org
Thu Jan 11 17:47:45 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()
I have two examples in JDK source code
1. 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
2. https://github.com/openjdk/jdk/blob/b78896b9aafcb15f453eaed6e154a5461581407b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java#L1606. In separate transformation, the `>` is transformed into `!=` (not sure why TBH), and both sides have invariants
Passes tier1 locally on Linux machine. Passes GHA on my fork.
-------------
Commit messages:
- 8323220: Reassociate loop invariants involved in Cmps and Add/Subs
Changes: https://git.openjdk.org/jdk/pull/17375/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=17375&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8323220
Stats: 270 lines in 3 files changed: 258 ins; 0 del; 12 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