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

Joshua Cao duke at openjdk.org
Tue Jan 23 18:36:27 UTC 2024


On Tue, 23 Jan 2024 01:08:06 GMT, Xin Liu <xliu at openjdk.org> wrote:

>> I am not following. We are explicitly checking for Cmp here. Why do we also need to check if it is a Sub?
>
> I think CmpNode has the same re-association rule as SubNode. 
> take your own example, 
>>  inv1 == (x - inv2) => ( inv1 + inv2 ) == x
> 
> Cmp(inv1, (x-inv2)) => Eq(0, Sub(inv1, (x-inv2)) => Eq(0, Sub(inv1+inv2, x)) => Cmp(inv1+inv2, x)
> 
> Originally, n1->is_Sub() covers both CmpNode and SubNode. I don't you need to split them it into 2 cases. 
> 
> I think you only to check if n1 Cmp or Sub when you are going to return Cmp/SubNode

The rules are not always the same. For example

> inv1 - (inv2 - x)     => (inv1 - inv2) + x
> inv1  == (inv2 - x) => (-inv1 + inv2) == x

The signs of inv1 and inv2 are flipped. I don't think we can fold these into a single conditional

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17375#discussion_r1463805762


More information about the hotspot-compiler-dev mailing list