RFR: 8336464: C2: Force CastX2P to be a two-address instruction
Vladimir Kozlov
kvn at openjdk.org
Tue Jul 30 17:43:33 UTC 2024
On Fri, 12 Jul 2024 13:59:23 GMT, Fei Gao <fgao at openjdk.org> wrote:
> This patch forces `CastX2P` to be a two-address instruction, so that C2 could allocate the same register for `dst` and `src`. Then we can remove the instruction completely in the assembly.
>
> The motivation comes from some cast operations like `castPP`. The difference for ADLC between `castPP` and `CastX2P` lies in that `CastX2P` always has different types for `dst` and `src`. We can force ADLC to generate an extra `two_adr()` for `CastX2P` like it does automatically for `castPP`, which could tell register allocator that the instruction needs the same register for `dst` and `src`.
>
> However, sometimes, RA and GCM in C2 can't work as we expected.
>
> For example, we have Assembly on the existing code:
>
> ldp x10, x11, [x17,#136]
> add x10, x10, x15
> add x11, x11, x10
> ldr x12, [x17,#152]
> str x16, [x10]
> add x10, x12, x15
> str x16, [x11]
> str x16, [x10]
>
>
> After applying the patch independently, the assembly is:
>
> ldr x10, [x16,#136] <--- 1
> add x10, x10, x15
> ldr x11, [x16,#144] <--- 2
> mov x13, x10 <--- 3
> str x17, [x13]
> ldr x12, [x16,#152]
> add x10, x11, x10
> str x17, [x10]
> add x10, x12, x15
> str x17, [x10]
>
>
> C2 generates a totally extra `mov`, see 3, and we even lost the chance to merge load pair, see 1 and 2. That's terrible.
>
> Although this scenario would disappear after combining with https://github.com/openjdk/jdk/pull/20157, I'm still not sure if this patch is worthwhile.
I am not sure about this change. There reason we keep `src `and `dst` in different register for different types is most likely for cases when `src` could be used in other operations. Overwriting `src` register may give you more spills than before.
If there are no other `src` usages RA should handle this I think in shared code.
-------------
PR Review: https://git.openjdk.org/jdk/pull/20159#pullrequestreview-2208305764
More information about the hotspot-compiler-dev
mailing list