]> git.ipfire.org Git - thirdparty/gcc.git/commit
aarch64: Add codegen support for AdvSIMD faminmax
authorSaurabh Jha <saurabh.jha@arm.com>
Wed, 7 Aug 2024 11:34:20 +0000 (12:34 +0100)
committerSaurabh Jha <saurabh.jha@arm.com>
Mon, 23 Sep 2024 16:26:49 +0000 (17:26 +0100)
commitc1fb78fb03caede01b02a1ebb3275ac98343d468
tree92befae6a21d398909ede405d3e1da700af47443
parentbfefed6c5bb62648cf0303d377c06cb45ab1f24a
aarch64: Add codegen support for AdvSIMD faminmax

The AArch64 FEAT_FAMINMAX extension is optional from Armv9.2-a and
mandatory from Armv9.5-a. It introduces instructions for computing the
floating point absolute maximum and minimum of the two vectors
element-wise.

This patch adds code generation support for famax and famin in terms of
existing RTL operators.

famax/famin is equivalent to first taking abs of the operands and then
taking smax/smin on the results of abs.

famax/famin (a, b) = smax/smin (abs (a), abs (b))

This fusion of operators is only possible when -march=armv9-a+faminmax
flags are passed. We also need to pass -ffast-math flag; if we don't,
then a statement like

c[i] = __builtin_fmaxf16 (a[i], b[i]);

is RTL expanded to UNSPEC_FMAXNM instead of smax (likewise for smin).

This code generation is only available on -O2 or -O3 as that is when
auto-vectorization is enabled.

gcc/ChangeLog:

* config/aarch64/aarch64-simd.md
(*aarch64_faminmax_fused): Instruction pattern for faminmax
codegen.
* config/aarch64/iterators.md: Attribute for faminmax codegen.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/simd/faminmax-codegen-no-flag.c: New test.
* gcc.target/aarch64/simd/faminmax-codegen.c: New test.
* gcc.target/aarch64/simd/faminmax-no-codegen.c: New test.
gcc/config/aarch64/aarch64-simd.md
gcc/config/aarch64/iterators.md
gcc/testsuite/gcc.target/aarch64/simd/faminmax-codegen-no-flag.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/simd/faminmax-codegen.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/simd/faminmax-no-codegen.c [new file with mode: 0644]