RFR: 8323220: Reassociate loop invariants involved in Cmps and Add/Subs [v4]
Emanuel Peter
epeter at openjdk.org
Wed Jan 24 09:08:30 UTC 2024
On Mon, 22 Jan 2024 21:58:42 GMT, Joshua Cao <duke at openjdk.org> wrote:
>> // 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:
>
> Formatting and fix typo
src/hotspot/share/opto/loopTransform.cpp line 333:
> 331: // inv1 == (inv2 - x) => (-inv1 + inv2 ) == x
> 332: //
> 333: Node* IdealLoopTree::reassociate_add_sub_cmp(Node* n1, int inv1_idx, int inv2_idx, PhaseIdealLoop* phase) {
as @navyxliu said, you should also update any comments with the old name. One thing I have spotted is this:
`//---------------------reassociate_add_sub------------------------`
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17375#discussion_r1464554665
More information about the hotspot-compiler-dev
mailing list