RFR: 8308340: C2: Idealize Fma nodes [v4]

Richard Reingruber rrich at openjdk.org
Mon Jul 17 14:31:18 UTC 2023


On Wed, 5 Jul 2023 11:11:22 GMT, Fei Gao <fgao at openjdk.org> wrote:

>> Some platforms, like aarch64, ppc, and riscv, support fusing `Math.fma(-a, b, c)` or `Math.fma(a, -b, c)` by generating partially symmetric match rules like:
>> 
>> 
>>   match(Set dst (FmaF src3 (Binary (NegF src1) src2)));
>>   match(Set dst (FmaF src3 (Binary src1 (NegF src2))));
>> 
>> 
>> Since `Fma` is partially commutative, the patch is to convert `Math.fma(-a, b, c)` to `Math.fma(b, -a, c)` in gvn phase, making node patterns canonical. Then we can remove redundant rules.
>> 
>> Also, we should guarantee that C2 generates `Fma` nodes only on platforms supporting `Fma` instructions before matcher, so we can remove all `predicate(UseFMA)` for all `Fma` rules.
>> 
>> After the patch, the code size of libjvm.so on aarch64 platform decreased by 63.4k.
>> 
>> The patch passed all tier 1 - 3 on aarch64 and x86 platforms.
>
> Fei Gao has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains five additional commits since the last revision:
> 
>  - Merge branch 'master' into fg8308340
>  - Merge branch 'master' into fg8308340
>  - Move check for UseFMA from c2compiler.cpp to Matcher::match_rule_supported in .ad files
>  - Merge branch 'master' into fg8308340
>  - 8308340: C2: Idealize Fma nodes
>    
>    Some platforms, like aarch64, ppc, and riscv, support fusing
>    `Math.fma(-a, b, c)` or `Math.fma(a, -b, c)` by generating
>    partially symmetric match rules like:
>    
>    ```
>      match(Set dst (FmaF src3 (Binary (NegF src1) src2)));
>      match(Set dst (FmaF src3 (Binary src1 (NegF src2))));
>    ```
>    
>    Since `Fma` is partially communitive, the patch is to convert
>    `Math.fma(-a, b, c)` to `Math.fma(b, -a, c)` in gvn phase,
>    making node patterns canonical. Then we can remove redundant
>    rules.
>    
>    Also, we should guarantee that C2 generates `Fma` nodes only on
>    platforms supporting `Fma` instructions before matcher, so we
>    can remove all `predicate(UseFMA)` for all `Fma` rules.
>    
>    After the patch, the code size of libjvm.so on aarch64 platform
>    decreased by 63.4k.
>    
>    The patch passed all tier 1 - 3 on aarch64 and x86 platforms.

src/hotspot/share/opto/vectornode.cpp line 1879:

> 1877: 
> 1878: Node* FmaVNode::Ideal(PhaseGVN* phase, bool can_reshape) {
> 1879:   // We canonicalize the node by converting "(-a)*b+c" into "b*(-a)+c"

Could you explain a little bit more please?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14576#discussion_r1265452868


More information about the hotspot-compiler-dev mailing list