AArch64: Fix left fold sum reduction RTL patterns [PR104049]
authorTamar Christina <tamar.christina@arm.com>
Thu, 7 Apr 2022 07:27:53 +0000 (08:27 +0100)
committerTamar Christina <tamar.christina@arm.com>
Thu, 7 Apr 2022 07:27:53 +0000 (08:27 +0100)
commit024edf08959e9c1d5022901e6c4e5cbaa5b6c8d5
tree17513f01d1c11672741ff1243864b6ceacf259f6
parentfdd81afcf18d1a926d81d63cc4525fc9442aa9a5
AArch64: Fix left fold sum reduction RTL patterns [PR104049]

As the discussion in the PR pointed out the RTL we have for the REDUC_PLUS
patterns are wrong.  The UNSPECs are modelled as returning a vector and then
in an expand pattern we emit a vec_select of the 0th element to get the scalar.

This is incorrect as the instruction itself already only returns a single scalar
and by declaring it returns a vector it allows combine to push in a subreg into
the pattern, which causes reload to make duplicate moves.

This patch corrects this by removing the weird indirection and making the RTL
pattern model the correct semantics of the instruction immediately.

gcc/ChangeLog:

PR target/104049
* config/aarch64/aarch64-simd.md
(aarch64_reduc_plus_internal<mode>): Fix RTL and rename to...
(reduc_plus_scal_<mode>): ... This.
(reduc_plus_scal_v4sf): Moved.
(aarch64_reduc_plus_internalv2si): Fix RTL and rename to...
(reduc_plus_scal_v2si): ... This.

gcc/testsuite/ChangeLog:

PR target/104049
* gcc.target/aarch64/vadd_reduc-1.c: New test.
* gcc.target/aarch64/vadd_reduc-2.c: New test.
gcc/config/aarch64/aarch64-simd.md
gcc/testsuite/gcc.target/aarch64/vadd_reduc-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/vadd_reduc-2.c [new file with mode: 0644]