Handle CONST_POLY_INTs in CONST_VECTORs [PR97141, PR98726]
authorRichard Sandiford <richard.sandiford@arm.com>
Wed, 31 Mar 2021 18:34:00 +0000 (19:34 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Wed, 31 Mar 2021 18:34:00 +0000 (19:34 +0100)
commit1b5f74e8be4dd7abe5624ff60adceff19ca71bda
treec6cebdef7424890265fa503a1d391050d1541021
parent23ce9945d5efa77c96161443f68e03664705ada3
Handle CONST_POLY_INTs in CONST_VECTORs [PR97141, PR98726]

This PR is caused by POLY_INT_CSTs being (necessarily) valid
in tree-level VECTOR_CSTs but CONST_POLY_INTs not being valid
in RTL CONST_VECTORs.  I can't tell/remember how deliberate
that was, but I'm guessing not very.  In particular,
valid_for_const_vector_p was added to guard against symbolic
constants rather than CONST_POLY_INTs.

I did briefly consider whether we should maintain the current
status anyway.  However, that would then require a way of
constructing variable-length vectors from individiual elements
if, say, we have:

   { [2, 2], [3, 2], [4, 2], … }

So I'm chalking this up to an oversight.  I think the intention
(and certainly the natural thing) is to have the same rules for
both trees and RTL.

The SVE CONST_VECTOR code should already be set up to handle
CONST_POLY_INTs.  However, we need to add support for Advanced SIMD
CONST_VECTORs that happen to contain SVE-based values.  The patch does
that by expanding such CONST_VECTORs in the same way as variable vectors.

gcc/
PR rtl-optimization/97141
PR rtl-optimization/98726
* emit-rtl.c (valid_for_const_vector_p): Return true for
CONST_POLY_INT_P.
* rtx-vector-builder.h (rtx_vector_builder::step): Return a
poly_wide_int instead of a wide_int.
(rtx_vector_builder::apply_set): Take a poly_wide_int instead
of a wide_int.
* rtx-vector-builder.c (rtx_vector_builder::apply_set): Likewise.
* config/aarch64/aarch64.c (aarch64_legitimate_constant_p): Return
false for CONST_VECTORs that cannot be forced to memory.
* config/aarch64/aarch64-simd.md (mov<mode>): If a CONST_VECTOR
is too complex to force to memory, build it up from individual
elements instead.

gcc/testsuite/
PR rtl-optimization/97141
PR rtl-optimization/98726
* gcc.c-torture/compile/pr97141.c: New test.
* gcc.c-torture/compile/pr98726.c: Likewise.
* gcc.target/aarch64/sve/pr97141.c: Likewise.
* gcc.target/aarch64/sve/pr98726.c: Likewise.
gcc/config/aarch64/aarch64-simd.md
gcc/config/aarch64/aarch64.c
gcc/emit-rtl.c
gcc/rtx-vector-builder.c
gcc/rtx-vector-builder.h
gcc/testsuite/gcc.c-torture/compile/pr97141.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/compile/pr98726.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/sve/pr97141.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/sve/pr98726.c [new file with mode: 0644]