https://gcc.gnu.org/g:33d8707f61d53def33b1f7138d2db07f57bc2ceb
commit r17-6680-g33d8707f61d53def33b1f7138d2db07f57bc2ceb Author: Christopher Bazley <[email protected]> Date: Thu Jul 30 14:56:42 2026 +0000 AArch64/SVE: Optimize aarch64_expand_sve_const_vector Prior to this change, the AArch64 code generated by GCC when the basic block SLP vectorizer had been extended with support for predicated tails was sometimes noticeably less efficient than equivalent code generated as a result of loop vectorization. This change helps to close the gap. For example, the following AArch64 assembly language was generated for an eight-byte constant with trailing zeros, {1,2,1,2,1,2,0,0}: ptrue p6.b, all ptrue p15.b, vl8 adrp x1, .LC0 movi d29, #0 ; zero-initialise z29 add x1, x1, :lo12:.LC0 ld1rd z30.d, p6/z, [x1] ; load 8-byte constant and ; duplicate it across z30 sel z29.b, p15, z30.b, z29.b ; copy first 8 bytes of ; z30, zero later lanes when a simple load would have sufficed (because ASIMD register d30 overlaps the lower bits of SVE register z30): adrp x1, .LANCHOR0 ldr d30, [x1, #:lo12:.LANCHOR0] ; load 8-byte constant, ; zero later lanes In this case, the vector constant can alternatively be constructed programmatically: mov w0, 513 movk x0, 0x201, lsl 16 movk x0, 0x201, lsl 32 fmov d0, x0 The cause was inappropriate use of the aarch64_expand_sve_const_vector_sel function, which builds a predicate mask and uses it to control whether the value of each lane of the expanded SVE CONST_VECTOR is copied from the first or second element of each pattern. Internally the vector constant from the above example is encoded by GCC as eight patterns, each of which has two elements: {1,0}, {2,0}, {1,0}, {2,0}, {1,0}, {2,0}, {0,0}, {0,0}. A new function has been created which checks whether the second element of every pattern is zero. If so, the new function builds a non-scalable vector from only the first element of each pattern, or if there is only one pattern, it uses the scalar constant value of its first element directly. For example, a builder with mode V8QI can be used to build an 8-byte representation of a constant that has partial vector mode VNx8QI and no more than four "foreground" element values. The supplied element values are interleaved with constant zeros. The resultant vector is placed in the constant pool (by force_const_mem). The scalar or vector constant is then loaded into a register that has the full SVE mode corresponding to the element type of CONST_VECTOR (e.g., VNx16QI instead of VNx8QI). An existing function, aarch64_emit_load_store_through_mode, has the required behaviour of emitting INSR to insert an element value into an SVE register whose values it has set to constant zero. It reinterprets both source and destination using the smallest scalar integer mode that can contain the fixed-size representation of the "foreground" elements of the vector constant (including any padding within each container), e.g., DImode to insert four lanes of a constant with mode VNx8QI. The whole optimisation is disabled for big-endian targets because the layout of ASIMD registers differs from SVE registers. It is also disabled for vector constants whose "foreground" elements would occupy more than a total width of 64 bits in an SVE register because full_mode = aarch64_full_sve_mode (as_a <scalar_mode> (TImode)).require (); would fail. (SVE has no 128-bit-element form of INSR.) These limitations could be addressed by future work. Single-byte loads are consistently lowered more efficiently by falling back to aarch64_expand_sve_const_vector_sel, so the new optimisation is disabled in those cases too. Assisted-by: ChatGPT (OpenAI) gcc/ChangeLog: * config/aarch64/aarch64.cc (aarch64_expand_sve_const_vector_zero_tail): New function that tries to expand a CONST_VECTOR that is encoded as N patterns, each pattern comprising a pair of elements in which the second element is zero. (aarch64_expand_sve_const_vector): Try calling aarch64_expand_sve_const_vector_zero_tail if each pattern comprises a pair of elements, and only use the existing aarch64_expand_sve_const_vector_sel function as a fallback. (aarch64_v16_mode): New function that chooses V2QImode or fails. (aarch64_v32_mode): New function that chooses V2HFmode, V2BFmode, V2HImode, V4QImode, or fails. (aarch64_simd_container_mode): Return via aarch64_v16_mode or aarch64_v32_mode if the passed-in vector width is known to be 16 or 32 bits respectively. gcc/testsuite/ChangeLog: * gcc.target/aarch64/sve/const_vector_zero_tail_1.c, gcc.target/aarch64/sve/const_vector_zero_tail_10.c, gcc.target/aarch64/sve/const_vector_zero_tail_10_run.c, gcc.target/aarch64/sve/const_vector_zero_tail_11.c, gcc.target/aarch64/sve/const_vector_zero_tail_11_run.c, gcc.target/aarch64/sve/const_vector_zero_tail_12.c, gcc.target/aarch64/sve/const_vector_zero_tail_13.c, gcc.target/aarch64/sve/const_vector_zero_tail_14.c, gcc.target/aarch64/sve/const_vector_zero_tail_15.c, gcc.target/aarch64/sve/const_vector_zero_tail_16.c, gcc.target/aarch64/sve/const_vector_zero_tail_17.c, gcc.target/aarch64/sve/const_vector_zero_tail_18.c, gcc.target/aarch64/sve/const_vector_zero_tail_19.c, gcc.target/aarch64/sve/const_vector_zero_tail_1_run.c, gcc.target/aarch64/sve/const_vector_zero_tail_2.c, gcc.target/aarch64/sve/const_vector_zero_tail_20.c, gcc.target/aarch64/sve/const_vector_zero_tail_21.c, gcc.target/aarch64/sve/const_vector_zero_tail_21_run.c, gcc.target/aarch64/sve/const_vector_zero_tail_22.c, gcc.target/aarch64/sve/const_vector_zero_tail_2_run.c, gcc.target/aarch64/sve/const_vector_zero_tail_3.c, gcc.target/aarch64/sve/const_vector_zero_tail_3_run.c, gcc.target/aarch64/sve/const_vector_zero_tail_4.c, gcc.target/aarch64/sve/const_vector_zero_tail_4_run.c, gcc.target/aarch64/sve/const_vector_zero_tail_5.c, gcc.target/aarch64/sve/const_vector_zero_tail_5_run.c, gcc.target/aarch64/sve/const_vector_zero_tail_6.c, gcc.target/aarch64/sve/const_vector_zero_tail_6_run.c, gcc.target/aarch64/sve/const_vector_zero_tail_7.c, gcc.target/aarch64/sve/const_vector_zero_tail_7_run.c, gcc.target/aarch64/sve/const_vector_zero_tail_8.c, gcc.target/aarch64/sve/const_vector_zero_tail_8_run.c, gcc.target/aarch64/sve/const_vector_zero_tail_9.c, gcc.target/aarch64/sve/const_vector_zero_tail_9_run.c: New tests. Diff: --- gcc/config/aarch64/aarch64.cc | 174 ++++++++++++++++++++- .../aarch64/sve/const_vector_zero_tail_1.c | 31 ++++ .../aarch64/sve/const_vector_zero_tail_10.c | 28 ++++ .../aarch64/sve/const_vector_zero_tail_10_run.c | 24 +++ .../aarch64/sve/const_vector_zero_tail_11.c | 28 ++++ .../aarch64/sve/const_vector_zero_tail_11_run.c | 24 +++ .../aarch64/sve/const_vector_zero_tail_12.c | 31 ++++ .../aarch64/sve/const_vector_zero_tail_13.c | 31 ++++ .../aarch64/sve/const_vector_zero_tail_14.c | 30 ++++ .../aarch64/sve/const_vector_zero_tail_15.c | 31 ++++ .../aarch64/sve/const_vector_zero_tail_16.c | 31 ++++ .../aarch64/sve/const_vector_zero_tail_17.c | 31 ++++ .../aarch64/sve/const_vector_zero_tail_18.c | 31 ++++ .../aarch64/sve/const_vector_zero_tail_19.c | 31 ++++ .../aarch64/sve/const_vector_zero_tail_1_run.c | 24 +++ .../aarch64/sve/const_vector_zero_tail_2.c | 30 ++++ .../aarch64/sve/const_vector_zero_tail_20.c | 31 ++++ .../aarch64/sve/const_vector_zero_tail_21.c | 30 ++++ .../aarch64/sve/const_vector_zero_tail_21_run.c | 24 +++ .../aarch64/sve/const_vector_zero_tail_22.c | 32 ++++ .../aarch64/sve/const_vector_zero_tail_2_run.c | 24 +++ .../aarch64/sve/const_vector_zero_tail_3.c | 30 ++++ .../aarch64/sve/const_vector_zero_tail_3_run.c | 24 +++ .../aarch64/sve/const_vector_zero_tail_4.c | 30 ++++ .../aarch64/sve/const_vector_zero_tail_4_run.c | 24 +++ .../aarch64/sve/const_vector_zero_tail_5.c | 28 ++++ .../aarch64/sve/const_vector_zero_tail_5_run.c | 24 +++ .../aarch64/sve/const_vector_zero_tail_6.c | 27 ++++ .../aarch64/sve/const_vector_zero_tail_6_run.c | 24 +++ .../aarch64/sve/const_vector_zero_tail_7.c | 28 ++++ .../aarch64/sve/const_vector_zero_tail_7_run.c | 24 +++ .../aarch64/sve/const_vector_zero_tail_8.c | 28 ++++ .../aarch64/sve/const_vector_zero_tail_8_run.c | 24 +++ .../aarch64/sve/const_vector_zero_tail_9.c | 28 ++++ .../aarch64/sve/const_vector_zero_tail_9_run.c | 24 +++ 35 files changed, 1114 insertions(+), 4 deletions(-) diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index bdd0db3fce91..0f4a1fab7a19 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -6480,6 +6480,129 @@ aarch64_expand_sve_ld1rq (rtx dest, rtx src) return true; } +/* SRC is an SVE CONST_VECTOR that contains N "foreground" values followed by N + "background" values, where N is the number of patterns and the number of + elements per pattern is 2. WIDTH is the number of vector register bits that + a complete set of N values would occupy in SRC. Try to move SRC into TARGET. + This requires the "background" values to be zero (as they often are) and + WIDTH to be small enough such that the "foreground" values can be moved + directly into the lower lanes of TARGET. If this is successful then + remaining lanes of TARGET are implicitly zero. + + Return the target on success, otherwise return null. */ + +static rtx +aarch64_expand_sve_const_vector_zero_tail (rtx target, rtx src, + unsigned int width) +{ + gcc_assert (CONST_VECTOR_NELTS_PER_PATTERN (src) == 2); + + machine_mode mode = GET_MODE (src); + scalar_mode elt_mode = GET_MODE_INNER (mode); + unsigned int npatterns = CONST_VECTOR_NPATTERNS (src); + unsigned int container_bits = aarch64_sve_container_bits (mode); + + gcc_checking_assert (container_bits * npatterns == width); + + if (width > 64 || BYTES_BIG_ENDIAN) + return NULL_RTX; + + /* Only single-byte loads are consistently lowered more efficiently by + falling back to aarch64_expand_sve_const_vector_sel. For example, this + predicated constant broadcast: + + ptrue p3.b, vl1 + mov z0.b, p3/z, #1 + + is preferable to this GPR-to-SIMD transfer and mask operation: + + mov w0, 1 + fmov h0, w0 + and z0.h, z0.h, #0xff + */ + if (npatterns == 1 && elt_mode == QImode) + return NULL_RTX; + + /* We can only handle cases where every "background" value of SRC is constant + zero, because those values describe an infinitely repeating tail. */ + for (unsigned int i = 0; i < npatterns; ++i) + if (CONST_VECTOR_ENCODED_ELT (src, i + npatterns) != CONST0_RTX (elt_mode)) + return NULL_RTX; + + machine_mode const_mode; + rtx const_val; + unsigned int elt_bits = GET_MODE_BITSIZE (elt_mode); + unsigned int load_width; + + if (npatterns == 1) + { + /* Use the scalar constant value of the first element directly. */ + const_val = CONST_VECTOR_ENCODED_ELT (src, 0); + const_mode = elt_mode; + load_width = elt_bits; + } + else + { + /* Build a non-scalable vector constant from the foreground values. */ + gcc_checking_assert (container_bits % elt_bits == 0); + unsigned int nelts_per_container = container_bits / elt_bits; + + /* We can't get CONST_MODE for a narrow vector, but that + does not matter because we can pad it. */ + load_width = MAX (width, 16); + + const_mode = aarch64_simd_container_mode (elt_mode, load_width); + + if (!VECTOR_MODE_P (const_mode)) + return NULL_RTX; + + unsigned int const_mem_nunits + = GET_MODE_NUNITS (const_mode).to_constant (); + if (npatterns * nelts_per_container > const_mem_nunits) + return NULL_RTX; + + rtx_vector_builder builder (const_mode, const_mem_nunits, 1); + for (unsigned int i = 0; i < npatterns; ++i) + { + rtx elt = CONST_VECTOR_ENCODED_ELT (src, i); + builder.quick_push (elt); + + /* Handle partial vector modes. For example, we can build a vector of + V8QImode (8 x 8-bit values) from SRC if WIDTH = 64, + MODE == VNx4QImode and N == 2 (i.e., 2 x 8-bit values in 32-bit + containers). Only one in four ELTs would be non-zero. */ + for (unsigned int p = 1; p < nelts_per_container; ++p) + { + builder.quick_push (CONST0_RTX (elt_mode)); + } + } + + for (unsigned int i = builder.length (); i < const_mem_nunits; ++i) + builder.quick_push (CONST0_RTX (elt_mode)); + + const_val = builder.build (); + } + + rtx val = force_const_mem (const_mode, const_val); + if (!val) + return NULL_RTX; + + /* Determine a machine mode, FULL_SVE_MODE, that has the same ELT_MODE + as MODE but is definitely not a partial vector mode (e.g., VNx16QImode + instead of VNx4QImode). */ + machine_mode full_sve_mode = aarch64_full_sve_mode (elt_mode).require (); + rtx full_sve = gen_reg_rtx (full_sve_mode); + + scalar_int_mode load_mode = int_mode_for_size (load_width, 0).require (); + aarch64_emit_load_store_through_mode (full_sve, val, load_mode); + + /* Reinterpret the temporary that has FULL_SVE_MODE (e.g., VNx16QImode) as + if it instead had MODE (e.g., VNx4QImode). */ + target = aarch64_target_reg (target, mode); + emit_insn (gen_aarch64_sve_reinterpret (mode, target, full_sve)); + return target; +} + /* SRC is an SVE CONST_VECTOR that contains N "foreground" values followed by N "background" values. Try to move it into TARGET using: @@ -6666,8 +6789,14 @@ aarch64_expand_sve_const_vector (rtx target, rtx src) return NULL_RTX; if (nelts_per_pattern == 2) - if (rtx res = aarch64_expand_sve_const_vector_sel (target, src)) - return res; + { + if (rtx res = aarch64_expand_sve_const_vector_zero_tail ( + target, src, encoded_bits / nelts_per_pattern)) + return res; + + if (rtx res = aarch64_expand_sve_const_vector_sel (target, src)) + return res; + } /* Expand each pattern individually. */ gcc_assert (npatterns > 1); @@ -24268,6 +24397,38 @@ aarch64_full_sve_mode (scalar_mode mode) } } +/* Return the 16-bit vector mode for element mode MODE, if it exists. */ +static opt_machine_mode +aarch64_v16_mode (scalar_mode mode) +{ + switch (mode) + { + case E_QImode: + return V2QImode; + default: + return {}; + } +} + +/* Return the 32-bit vector mode for element mode MODE, if it exists. */ +static opt_machine_mode +aarch64_v32_mode (scalar_mode mode) +{ + switch (mode) + { + case E_HFmode: + return V2HFmode; + case E_BFmode: + return V2BFmode; + case E_HImode: + return V2HImode; + case E_QImode: + return V4QImode; + default: + return {}; + } +} + /* Return the 64-bit Advanced SIMD vector mode for element mode MODE, if it exists. */ opt_machine_mode @@ -24330,13 +24491,18 @@ aarch64_simd_container_mode (scalar_mode mode, poly_int64 width) && known_eq (width, BITS_PER_SVE_VECTOR)) return aarch64_full_sve_mode (mode).else_mode (word_mode); - gcc_assert (known_eq (width, 64) || known_eq (width, 128)); + gcc_assert (known_eq (width, 16) || known_eq (width, 32) + || known_eq (width, 64) || known_eq (width, 128)); if (TARGET_BASE_SIMD) { if (known_eq (width, 128)) return aarch64_v128_mode (mode).else_mode (word_mode); - else + if (known_eq (width, 64)) return aarch64_v64_mode (mode).else_mode (word_mode); + if (known_eq (width, 32)) + return aarch64_v32_mode (mode).else_mode (word_mode); + if (known_eq (width, 16)) + return aarch64_v16_mode (mode).else_mode (word_mode); } return word_mode; } diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_1.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_1.c new file mode 100644 index 000000000000..83bb69a85f38 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_1.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 7 explicitly initialized + 8-bit integer elements can be loaded with a single Advanced SIMD doubleword + load or GPR-to-SIMD move. The remaining elements are zero, including those + beyond the minimum SVE vector length. */ + +#include <arm_sve.h> + +#define LIT _Literal (uint8_t) + +svuint8_t +__GIMPLE (startwith ("expand")) f (void) +{ + svuint8_t v; + + v = _Literal (svuint8_t){ + LIT 1, LIT 2, LIT 1, LIT 2, + LIT 1, LIT 2, LIT 1 + }; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\td[0-9]+,|\tfmov\td[0-9]+, x[0-9]+)} 1 } } */ + +/* The general-purpose expansion instead broadcasts a short repeated vector and + then selects only the low elements. */ +/* { dg-final { scan-assembler-not {\tld1rd\t} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_10.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_10.c new file mode 100644 index 000000000000..a2364ec6dda9 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_10.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 1 explicitly initialized + 16-bit floating-point element can be loaded with a single Advanced SIMD + halfword load or GPR-to-SIMD move. The remaining elements are zero, + including those beyond the minimum SVE vector length. */ + +#include <arm_sve.h> + +#define LIT _Literal (float16_t) + +svfloat16_t +__GIMPLE (startwith ("expand")) f (void) +{ + svfloat16_t v; + + v = _Literal (svfloat16_t){LIT 1.234375f}; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\th[0-9]+,|\tfmov\th[0-9]+, w[0-9]+)} 1 } } */ + +/* It is less efficient to broadcast a short repeated vector and then select + only the low elements. */ +/* { dg-final { scan-assembler-not {\tmov\tz[0-9]+\.h,} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_10_run.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_10_run.c new file mode 100644 index 000000000000..bff2b391d43a --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_10_run.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-require-effective-target aarch64_sve_hw } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +#include "const_vector_zero_tail_10.c" + +int +main (void) +{ + unsigned long n = svcnth (); + float16_t result[n]; + + svst1_f16 (svptrue_b16 (), result, f ()); + + for (unsigned long i = 0; i < n; ++i) + { + float16_t expected = i < 1 ? 1.234375f : 0; + + if (result[i] != expected) + __builtin_abort (); + } + + return 0; +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_11.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_11.c new file mode 100644 index 000000000000..e73304934ef3 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_11.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 2 explicitly initialized + 16-bit integer elements can be loaded with a single Advanced SIMD word load + or GPR-to-SIMD move. The remaining elements are zero, including those beyond + the minimum SVE vector length. */ + +#include <arm_sve.h> + +#define LIT _Literal (uint16_t) + +svuint16_t +__GIMPLE (startwith ("expand")) f (void) +{ + svuint16_t v; + + v = _Literal (svuint16_t){LIT 1, LIT 2}; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\ts[0-9]+,|\tfmov\ts[0-9]+, w[0-9]+)} 1 } } */ + +/* It is less efficient to broadcast a short repeated vector and then select + only the low elements. */ +/* { dg-final { scan-assembler-not {\tld1rw\t} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_11_run.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_11_run.c new file mode 100644 index 000000000000..5dcc3367be32 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_11_run.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-require-effective-target aarch64_sve_hw } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +#include "const_vector_zero_tail_11.c" + +int +main (void) +{ + unsigned long n = svcnth (); + uint16_t result[n]; + + svst1_u16 (svptrue_b16 (), result, f ()); + + for (unsigned long i = 0; i < n; ++i) + { + uint16_t expected = i < 2 ? (i & 1 ? 2 : 1) : 0; + + if (result[i] != expected) + __builtin_abort (); + } + + return 0; +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_12.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_12.c new file mode 100644 index 000000000000..612b3b340bea --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_12.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 2 explicitly initialized + 8-bit integer elements in 16-bit containers can be loaded with a single + Advanced SIMD word load or GPR-to-SIMD move. The remaining elements are + zero, including those beyond the minimum SVE vector length. */ + +#include <arm_sve.h> + +typedef uint8_t vnx8qi __attribute__ ((mode (VNx8QI))); /* { dg-warning "specifying vector types.*deprecated" } */ +/* { dg-message "use .*vector_size.* instead" "" { target *-*-* } .-1 } */ + +#define LIT _Literal (uint8_t) + +vnx8qi +__GIMPLE (startwith ("expand")) f (void) +{ + vnx8qi v; + + v = _Literal (vnx8qi){LIT 1, LIT 2}; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\ts[0-9]+,|\tfmov\ts[0-9]+, w[0-9]+)} 1 } } */ + +/* It is less efficient to broadcast a short repeated vector and then select + only the low elements. */ +/* { dg-final { scan-assembler-not {\tld1rw\t} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_13.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_13.c new file mode 100644 index 000000000000..b1a90f3a60cf --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_13.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 2 explicitly initialized + 8-bit integer elements in 32-bit containers can be loaded with a single + Advanced SIMD doubleword load or GPR-to-SIMD move. The remaining elements + are zero, including those beyond the minimum SVE vector length. */ + +#include <arm_sve.h> + +typedef uint8_t vnx4qi __attribute__ ((mode (VNx4QI))); /* { dg-warning "specifying vector types.*deprecated" } */ +/* { dg-message "use .*vector_size.* instead" "" { target *-*-* } .-1 } */ + +#define LIT _Literal (uint8_t) + +vnx4qi +__GIMPLE (startwith ("expand")) f (void) +{ + vnx4qi v; + + v = _Literal (vnx4qi){LIT 1, LIT 2}; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\td[0-9]+,|\tfmov\td[0-9]+, x[0-9]+)} 1 } } */ + +/* It is less efficient to broadcast a short repeated vector and then select + only the low elements. */ +/* { dg-final { scan-assembler-not {\tld1rd\t} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_14.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_14.c new file mode 100644 index 000000000000..a5475e89ec66 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_14.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 1 explicitly initialized + 8-bit integer element in a 64-bit container is not loaded with a single + Advanced SIMD byte load or GPR-to-SIMD halfword move because it would not be + profitable. (There is no fmov bN.) */ + +#include <arm_sve.h> + +typedef uint8_t vnx2qi __attribute__ ((mode (VNx2QI))); /* { dg-warning "specifying vector types.*deprecated" } */ +/* { dg-message "use .*vector_size.* instead" "" { target *-*-* } .-1 } */ + +#define LIT _Literal (uint8_t) + +vnx2qi +__GIMPLE (startwith ("expand")) f (void) +{ + vnx2qi v; + + v = _Literal (vnx2qi){LIT 1}; + + return v; +} + +/* { dg-final { scan-assembler-not {(\tldr\tb[0-9]+,|\tfmov\th[0-9]+, w[0-9]+)} } } */ + +/* It is more efficient to use a zeroing predicated move. */ +/* { dg-final { scan-assembler-times {\tptrue\tp[0-9]+\.b, vl1} 1 } } */ +/* { dg-final { scan-assembler-times {\tmov\tz[0-9]+\.b, p[0-9]+/z,} 1 } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_15.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_15.c new file mode 100644 index 000000000000..d588e7542225 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_15.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 1 explicitly initialized + 32-bit integer element in a 64-bit container can be loaded with a single + Advanced SIMD word load or GPR-to-SIMD move. The remaining elements are + zero, including those beyond the minimum SVE vector length. */ + +#include <arm_sve.h> + +typedef uint32_t vnx2si __attribute__ ((mode (VNx2SI))); /* { dg-warning "specifying vector types.*deprecated" } */ +/* { dg-message "use .*vector_size.* instead" "" { target *-*-* } .-1 } */ + +#define LIT _Literal (uint32_t) + +vnx2si +__GIMPLE (startwith ("expand")) f (void) +{ + vnx2si v; + + v = _Literal (vnx2si){LIT 0x12345678}; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\ts[0-9]+,|\tfmov\ts[0-9]+, w[0-9]+)} 1 } } */ + +/* It is less efficient to broadcast a short repeated vector and then select + only the low elements. */ +/* { dg-final { scan-assembler-not {\tld1rw\t} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_16.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_16.c new file mode 100644 index 000000000000..143112ad75be --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_16.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 1 explicitly initialized + 32-bit floating-point element in a 64-bit container can be loaded with a + single Advanced SIMD word load or GPR-to-SIMD move. The remaining elements + are zero, including those beyond the minimum SVE vector length. */ + +#include <arm_sve.h> + +typedef float32_t vnx2sf __attribute__ ((mode (VNx2SF))); /* { dg-warning "specifying vector types.*deprecated" } */ +/* { dg-message "use .*vector_size.* instead" "" { target *-*-* } .-1 } */ + +#define LIT _Literal (float32_t) + +vnx2sf +__GIMPLE (startwith ("expand")) f (void) +{ + vnx2sf v; + + v = _Literal (vnx2sf){LIT 1.234375f}; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\ts[0-9]+,|\tfmov\ts[0-9]+, w[0-9]+)} 1 } } */ + +/* It is less efficient to broadcast a short repeated vector and then select + only the low elements. */ +/* { dg-final { scan-assembler-not {\tmov\tz[0-9]+\.s,} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_17.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_17.c new file mode 100644 index 000000000000..1601a3523c6f --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_17.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 2 explicitly initialized + 16-bit floating-point elements in 32-bit containers can be loaded with a + single Advanced SIMD doubleword load or GPR-to-SIMD move. The remaining + elements are zero, including those beyond the minimum SVE vector length. */ + +#include <arm_sve.h> + +typedef float16_t vnx4hf __attribute__ ((mode (VNx4HF))); /* { dg-warning "specifying vector types.*deprecated" } */ +/* { dg-message "use .*vector_size.* instead" "" { target *-*-* } .-1 } */ + +#define LIT _Literal (float16_t) + +vnx4hf +__GIMPLE (startwith ("expand")) f (void) +{ + vnx4hf v; + + v = _Literal (vnx4hf){LIT 1, LIT 2}; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\td[0-9]+,|\tfmov\td[0-9]+, x[0-9]+)} 1 } } */ + +/* It is less efficient to broadcast a short repeated vector and then select + only the low elements. */ +/* { dg-final { scan-assembler-not {\tld1rd\t} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_18.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_18.c new file mode 100644 index 000000000000..a5794e1aa591 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_18.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 4 explicitly initialized + 8-bit integer elements in 16-bit containers can be loaded with a + single Advanced SIMD doubleword load or GPR-to-SIMD move. The remaining + elements are zero, including those beyond the minimum SVE vector length. */ + +#include <arm_sve.h> + +typedef uint8_t vnx8qi __attribute__ ((mode (VNx8QI))); /* { dg-warning "specifying vector types.*deprecated" } */ +/* { dg-message "use .*vector_size.* instead" "" { target *-*-* } .-1 } */ + +#define LIT _Literal (uint8_t) + +vnx8qi +__GIMPLE (startwith ("expand")) f (void) +{ + vnx8qi v; + + v = _Literal (vnx8qi){LIT 1, LIT 2, LIT 1, LIT 2}; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\td[0-9]+,|\tfmov\td[0-9]+, x[0-9]+)} 1 } } */ + +/* It is less efficient to broadcast a short repeated vector and then select + only the low elements. */ +/* { dg-final { scan-assembler-not {\tld1rw\t} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_19.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_19.c new file mode 100644 index 000000000000..78ae007708c8 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_19.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 2 explicitly initialized + 16-bit integer elements in 32-bit containers can be loaded with a + single Advanced SIMD doubleword load or GPR-to-SIMD move. The remaining + elements are zero, including those beyond the minimum SVE vector length. */ + +#include <arm_sve.h> + +typedef uint16_t vnx4hi __attribute__ ((mode (VNx4HI))); /* { dg-warning "specifying vector types.*deprecated" } */ +/* { dg-message "use .*vector_size.* instead" "" { target *-*-* } .-1 } */ + +#define LIT _Literal (uint16_t) + +vnx4hi +__GIMPLE (startwith ("expand")) f (void) +{ + vnx4hi v; + + v = _Literal (vnx4hi){LIT 1, LIT 2}; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\td[0-9]+,|\tfmov\td[0-9]+, x[0-9]+)} 1 } } */ + +/* It is less efficient to broadcast a short repeated vector and then select + only the low elements. */ +/* { dg-final { scan-assembler-not {\tld1rd\t} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_1_run.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_1_run.c new file mode 100644 index 000000000000..ab12629d62a4 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_1_run.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-require-effective-target aarch64_sve_hw } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +#include "const_vector_zero_tail_1.c" + +int +main (void) +{ + unsigned long n = svcntb (); + uint8_t result[n]; + + svst1_u8 (svptrue_b8 (), result, f ()); + + for (unsigned long i = 0; i < n; ++i) + { + uint8_t expected = i < 7 ? (i & 1 ? 2 : 1) : 0; + + if (result[i] != expected) + __builtin_abort (); + } + + return 0; +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_2.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_2.c new file mode 100644 index 000000000000..45f851be6906 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_2.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 3 explicitly initialized + 8-bit integer elements can be loaded with a single Advanced SIMD word load or + GPR-to-SIMD move. The remaining elements are zero, including those beyond the + minimum SVE vector length. */ + +#include <arm_sve.h> + +#define LIT _Literal (uint8_t) + +svuint8_t +__GIMPLE (startwith ("expand")) f (void) +{ + svuint8_t v; + + v = _Literal (svuint8_t){ + LIT 1, LIT 2, LIT 1 + }; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\ts[0-9]+,|\tfmov\ts[0-9]+, w[0-9]+)} 1 } } */ + +/* The general-purpose expansion instead broadcasts a short repeated vector and + then selects only the low elements. */ +/* { dg-final { scan-assembler-not {\tld1rw\t} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_20.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_20.c new file mode 100644 index 000000000000..4a8aea516522 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_20.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 8 explicitly initialized + 8-bit integer elements can be loaded with a single Advanced SIMD doubleword + load or GPR-to-SIMD move. The remaining elements are zero, including those + beyond the minimum SVE vector length. */ + +#include <arm_sve.h> + +#define LIT _Literal (uint8_t) + +svuint8_t +__GIMPLE (startwith ("expand")) f (void) +{ + svuint8_t v; + + v = _Literal (svuint8_t){ + LIT 1, LIT 2, LIT 1, LIT 2, + LIT 1, LIT 2, LIT 1, LIT 2 + }; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\td[0-9]+,|\tfmov\td[0-9]+, x[0-9]+)} 1 } } */ + +/* The general-purpose expansion instead broadcasts a short repeated vector and + then selects only the low elements. */ +/* { dg-final { scan-assembler-not {\tmov\tz[0-9]+\.h, w[0-9]+} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_21.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_21.c new file mode 100644 index 000000000000..2aaff3a568bb --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_21.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* A scalable vector constant with 9 explicitly initialized 8-bit integer + elements cannot currently be loaded with an Advanced SIMD quadword load or + GPR-to-SIMD move, but it's still a boundary condition worth testing. + */ + +#include <arm_sve.h> + +#define LIT _Literal (uint8_t) + +svuint8_t +__GIMPLE (startwith ("expand")) f (void) +{ + svuint8_t v; + + v = _Literal (svuint8_t){ + LIT 1, LIT 2, LIT 1, LIT 2, + LIT 1, LIT 2, LIT 1, LIT 2, + LIT 1 + }; + + return v; +} + +/* The general-purpose expansion broadcasts a short repeated vector and + then selects only the low elements. */ +/* { dg-final { scan-assembler-times {\tld1rqb\t} 1 } } */ +/* { dg-final { scan-assembler-times {\tsel\tz[0-9]+} 1 } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_21_run.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_21_run.c new file mode 100644 index 000000000000..a85c74bbc0f1 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_21_run.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-require-effective-target aarch64_sve_hw } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +#include "const_vector_zero_tail_21.c" + +int +main (void) +{ + unsigned long n = svcntb (); + uint8_t result[n]; + + svst1_u8 (svptrue_b8 (), result, f ()); + + for (unsigned long i = 0; i < n; ++i) + { + uint8_t expected = i < 9 ? (i & 1 ? 2 : 1) : 0; + + if (result[i] != expected) + __builtin_abort (); + } + + return 0; +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_22.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_22.c new file mode 100644 index 000000000000..149129f5842a --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_22.c @@ -0,0 +1,32 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 8 explicitly initialized + 8-bit integer elements that have only a final non-zero value can be + loaded with a single Advanced SIMD doubleword load or GPR-to-SIMD move. The + remaining elements are zero, including those beyond the minimum SVE vector + length. */ + +#include <arm_sve.h> + +#define LIT _Literal (uint8_t) + +svuint8_t +__GIMPLE (startwith ("expand")) f (void) +{ + svuint8_t v; + + v = _Literal (svuint8_t){ + LIT 0, LIT 0, LIT 0, LIT 0, + LIT 0, LIT 0, LIT 0, LIT 1 + }; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\td[0-9]+,|\tfmov\td[0-9]+, x[0-9]+)} 1 } } */ + +/* The general-purpose expansion instead broadcasts a short repeated vector and + then selects only the low elements. */ +/* { dg-final { scan-assembler-not {\tmov\tz[0-9]+\.d,} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_2_run.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_2_run.c new file mode 100644 index 000000000000..12125b8a2fad --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_2_run.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-require-effective-target aarch64_sve_hw } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +#include "const_vector_zero_tail_2.c" + +int +main (void) +{ + unsigned long n = svcntb (); + uint8_t result[n]; + + svst1_u8 (svptrue_b8 (), result, f ()); + + for (unsigned long i = 0; i < n; ++i) + { + uint8_t expected = i < 3 ? (i & 1 ? 2 : 1) : 0; + + if (result[i] != expected) + __builtin_abort (); + } + + return 0; +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_3.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_3.c new file mode 100644 index 000000000000..cb8f460e5428 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_3.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 3 explicitly initialized + 16-bit integer elements can be loaded with a single Advanced SIMD doubleword + load or GPR-to-SIMD move. The remaining elements are zero, including those + beyond the minimum SVE vector length. */ + +#include <arm_sve.h> + +#define LIT _Literal (uint16_t) + +svuint16_t +__GIMPLE (startwith ("expand")) f (void) +{ + svuint16_t v; + + v = _Literal (svuint16_t){ + LIT 1, LIT 2, LIT 1 + }; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\td[0-9]+,|\tfmov\td[0-9]+, x[0-9]+)} 1 } } */ + +/* The general-purpose expansion instead broadcasts a short repeated vector and + then selects only the low elements. */ +/* { dg-final { scan-assembler-not {\tld1rd\t} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_3_run.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_3_run.c new file mode 100644 index 000000000000..38c26ade8091 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_3_run.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-require-effective-target aarch64_sve_hw } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +#include "const_vector_zero_tail_3.c" + +int +main (void) +{ + unsigned long n = svcnth (); + uint16_t result[n]; + + svst1_u16 (svptrue_b16 (), result, f ()); + + for (unsigned long i = 0; i < n; ++i) + { + uint16_t expected = i < 3 ? (i & 1 ? 2 : 1) : 0; + + if (result[i] != expected) + __builtin_abort (); + } + + return 0; +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_4.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_4.c new file mode 100644 index 000000000000..1e7118860b45 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_4.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 3 explicitly initialized + 16-bit floating-point elements can be loaded with a single Advanced SIMD + doubleword load or GPR-to-SIMD move. The remaining elements are zero, + including those beyond the minimum SVE vector length. */ + +#include <arm_sve.h> + +#define LIT _Literal (float16_t) + +svfloat16_t +__GIMPLE (startwith ("expand")) f (void) +{ + svfloat16_t v; + + v = _Literal (svfloat16_t){ + LIT 1.0f, LIT 2.0f, LIT 3.0f + }; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\td[0-9]+,|\tfmov\td[0-9]+, x[0-9]+)} 1 } } */ + +/* The general-purpose expansion instead broadcasts a short repeated vector and + then selects only the low elements. */ +/* { dg-final { scan-assembler-not {\tld1rd\t} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_4_run.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_4_run.c new file mode 100644 index 000000000000..9d0d3751cf8f --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_4_run.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-require-effective-target aarch64_sve_hw } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +#include "const_vector_zero_tail_4.c" + +int +main (void) +{ + unsigned long n = svcnth (); + float16_t result[n]; + + svst1_f16 (svptrue_b16 (), result, f ()); + + for (unsigned long i = 0; i < n; ++i) + { + float16_t expected = i < 3 ? (i + 1) : 0; + + if (result[i] != expected) + __builtin_abort (); + } + + return 0; +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_5.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_5.c new file mode 100644 index 000000000000..345b284d2f89 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_5.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 1 explicitly initialized + 64-bit integer element can be loaded with a single Advanced SIMD doubleword + load or GPR-to-SIMD move. The remaining elements are zero, including those + beyond the minimum SVE vector length. */ + +#include <arm_sve.h> + +#define LIT _Literal (uint64_t) + +svuint64_t +__GIMPLE (startwith ("expand")) f (void) +{ + svuint64_t v; + + v = _Literal (svuint64_t){LIT 0x123456789abcdef0ULL}; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\td[0-9]+,|\tfmov\td[0-9]+, x[0-9]+)} 1 } } */ + +/* The general-purpose expansion instead broadcasts a short repeated vector and + then selects only the low elements. */ +/* { dg-final { scan-assembler-not {\tld1rd\t} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_5_run.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_5_run.c new file mode 100644 index 000000000000..f0628052ace8 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_5_run.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-require-effective-target aarch64_sve_hw } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +#include "const_vector_zero_tail_5.c" + +int +main (void) +{ + unsigned long n = svcntd (); + uint64_t result[n]; + + svst1_u64 (svptrue_b64 (), result, f ()); + + for (unsigned long i = 0; i < n; ++i) + { + uint64_t expected = i < 1 ? 0x123456789abcdef0ULL : 0; + + if (result[i] != expected) + __builtin_abort (); + } + + return 0; +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_6.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_6.c new file mode 100644 index 000000000000..7513a76028d8 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_6.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 1 explicitly initialized + 8-bit integer element is not loaded with a single Advanced SIMD byte load + or halfword GPR-to-SIMD move because it would not be profitable. (There is + no fmov bN.) */ + +#include <arm_sve.h> + +#define LIT _Literal (uint8_t) + +svuint8_t +__GIMPLE (startwith ("expand")) f (void) +{ + svuint8_t v; + + v = _Literal (svuint8_t){LIT 1}; + + return v; +} + +/* { dg-final { scan-assembler-not {(\tldr\tb[0-9]+,|\tfmov\th[0-9]+, w[0-9]+)} } } */ + +/* It is more efficient to use a zeroing predicated move. */ +/* { dg-final { scan-assembler-times {\tptrue\tp[0-9]+\.b, vl1} 1 } } */ +/* { dg-final { scan-assembler-times {\tmov\tz[0-9]+\.b, p[0-9]+/z,} 1 } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_6_run.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_6_run.c new file mode 100644 index 000000000000..f57ba7a29ae8 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_6_run.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-require-effective-target aarch64_sve_hw } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +#include "const_vector_zero_tail_6.c" + +int +main (void) +{ + unsigned long n = svcntb (); + uint8_t result[n]; + + svst1_u8 (svptrue_b8 (), result, f ()); + + for (unsigned long i = 0; i < n; ++i) + { + uint8_t expected = i < 1 ? 1 : 0; + + if (result[i] != expected) + __builtin_abort (); + } + + return 0; +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_7.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_7.c new file mode 100644 index 000000000000..03cf1d313525 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_7.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 2 explicitly initialized + 8-bit integer elements can be loaded with a single Advanced SIMD halfword + load or GPR-to-SIMD move. The remaining elements are zero, including those + beyond the minimum SVE vector length. */ + +#include <arm_sve.h> + +#define LIT _Literal (uint8_t) + +svuint8_t +__GIMPLE (startwith ("expand")) f (void) +{ + svuint8_t v; + + v = _Literal (svuint8_t){LIT 1, LIT 2}; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\th[0-9]+,|\tfmov\th[0-9]+, w[0-9]+)} 1 } } */ + +/* It is less efficient to broadcast a short repeated vector and then select + only the low elements. */ +/* { dg-final { scan-assembler-not {\tmov\tz[0-9]+\.h,} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_7_run.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_7_run.c new file mode 100644 index 000000000000..50a487e1ac11 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_7_run.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-require-effective-target aarch64_sve_hw } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +#include "const_vector_zero_tail_7.c" + +int +main (void) +{ + unsigned long n = svcntb (); + uint8_t result[n]; + + svst1_u8 (svptrue_b8 (), result, f ()); + + for (unsigned long i = 0; i < n; ++i) + { + uint8_t expected = i < 2 ? (i & 1 ? 2 : 1) : 0; + + if (result[i] != expected) + __builtin_abort (); + } + + return 0; +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_8.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_8.c new file mode 100644 index 000000000000..a9ba3dda5257 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_8.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 1 explicitly initialized + 64-bit floating-point element can be loaded with a single Advanced SIMD + doubleword load or GPR-to-SIMD move. The remaining elements are zero, + including those beyond the minimum SVE vector length. */ + +#include <arm_sve.h> + +#define LIT _Literal (float64_t) + +svfloat64_t +__GIMPLE (startwith ("expand")) f (void) +{ + svfloat64_t v; + + v = _Literal (svfloat64_t){LIT 1.234375f}; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\td[0-9]+,|\tfmov\td[0-9]+, x[0-9]+)} 1 } } */ + +/* It is less efficient to broadcast a short repeated vector and then select + only the low elements. */ +/* { dg-final { scan-assembler-not {\tld1rd\t} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_8_run.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_8_run.c new file mode 100644 index 000000000000..00f5ed3a1fb3 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_8_run.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-require-effective-target aarch64_sve_hw } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +#include "const_vector_zero_tail_8.c" + +int +main (void) +{ + unsigned long n = svcntd (); + float64_t result[n]; + + svst1_f64 (svptrue_b64 (), result, f ()); + + for (unsigned long i = 0; i < n; ++i) + { + float64_t expected = i < 1 ? 1.234375f : 0; + + if (result[i] != expected) + __builtin_abort (); + } + + return 0; +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_9.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_9.c new file mode 100644 index 000000000000..95ced33a0bff --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_9.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +/* Check that a scalable vector constant with 1 explicitly initialized + 32-bit integer element can be loaded with a single Advanced SIMD word load or + GPR-to-SIMD move. The remaining elements are zero, including those beyond + the minimum SVE vector length. */ + +#include <arm_sve.h> + +#define LIT _Literal (uint32_t) + +svuint32_t +__GIMPLE (startwith ("expand")) f (void) +{ + svuint32_t v; + + v = _Literal (svuint32_t){LIT 0x12345678}; + + return v; +} + +/* { dg-final { scan-assembler-times {(\tldr\ts[0-9]+,|\tfmov\ts[0-9]+, w[0-9]+)} 1 } } */ + +/* It is less efficient to broadcast a short repeated vector and then select + only the low elements. */ +/* { dg-final { scan-assembler-not {\tld1rw\t} } } */ +/* { dg-final { scan-assembler-not {\tsel\tz[0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_9_run.c b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_9_run.c new file mode 100644 index 000000000000..6b3db0091af9 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/const_vector_zero_tail_9_run.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-require-effective-target aarch64_sve_hw } */ +/* { dg-options "-O2 -fgimple -msve-vector-bits=scalable" } */ + +#include "const_vector_zero_tail_9.c" + +int +main (void) +{ + unsigned long n = svcntw (); + uint32_t result[n]; + + svst1_u32 (svptrue_b32 (), result, f ()); + + for (unsigned long i = 0; i < n; ++i) + { + uint32_t expected = i < 1 ? 0x12345678 : 0; + + if (result[i] != expected) + __builtin_abort (); + } + + return 0; +}
