aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2021-04-14 16:19:46 +0100
committerRichard Sandiford <richard.sandiford@arm.com>2021-04-14 16:19:46 +0100
commita065e0bb092a010664777394530ab1a52bb5293b (patch)
treeea7b3fa6d9e02b10b6ead9ba4cec1d50a38a1c85 /gcc
parent3191c1f4488d1f7563b563d7ae2a102a26f16d82 (diff)
downloadgcc-a065e0bb092a010664777394530ab1a52bb5293b.zip
gcc-a065e0bb092a010664777394530ab1a52bb5293b.tar.gz
gcc-a065e0bb092a010664777394530ab1a52bb5293b.tar.bz2
aarch64: Handle more SVE vector constants [PR99246]
PR99246 is about a case in which we failed to handle a CONST_VECTOR with NELTS_PER_PATTERN==2, i.e. a vector with a “foreground” sequence of N vectors followed by a repeating “background” sequence of N vectors. At the moment, it's difficult to produce these vectors directly, but I'm hoping that for GCC 12 we'll do more folding, which will in turn make this easier to test and easier to optimise. Until then, the patch simply relies on the testcase in the PR. gcc/ PR target/99246 * config/aarch64/aarch64.c (aarch64_expand_sve_const_vector_sel): New function. (aarch64_expand_sve_const_vector): Use it for nelts_per_pattern==2. gcc/testsuite/ PR target/99246 * gcc.target/aarch64/sve/acle/general/pr99246.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config/aarch64/aarch64.c54
-rw-r--r--gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr99246.c17
2 files changed, 71 insertions, 0 deletions
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 6405504..04b55d9 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -5166,6 +5166,56 @@ 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. Try to move it into TARGET using:
+
+ PTRUE PRED.<T>, VL<N>
+ MOV TRUE.<T>, #<foreground>
+ MOV FALSE.<T>, #<background>
+ SEL TARGET.<T>, PRED.<T>, TRUE.<T>, FALSE.<T>
+
+ The PTRUE is always a single instruction but the MOVs might need a
+ longer sequence. If the background value is zero (as it often is),
+ the sequence can sometimes collapse to a PTRUE followed by a
+ zero-predicated move.
+
+ Return the target on success, otherwise return null. */
+
+static rtx
+aarch64_expand_sve_const_vector_sel (rtx target, rtx src)
+{
+ gcc_assert (CONST_VECTOR_NELTS_PER_PATTERN (src) == 2);
+
+ /* Make sure that the PTRUE is valid. */
+ machine_mode mode = GET_MODE (src);
+ machine_mode pred_mode = aarch64_sve_pred_mode (mode);
+ unsigned int npatterns = CONST_VECTOR_NPATTERNS (src);
+ if (aarch64_svpattern_for_vl (pred_mode, npatterns)
+ == AARCH64_NUM_SVPATTERNS)
+ return NULL_RTX;
+
+ rtx_vector_builder pred_builder (pred_mode, npatterns, 2);
+ rtx_vector_builder true_builder (mode, npatterns, 1);
+ rtx_vector_builder false_builder (mode, npatterns, 1);
+ for (unsigned int i = 0; i < npatterns; ++i)
+ {
+ true_builder.quick_push (CONST_VECTOR_ENCODED_ELT (src, i));
+ pred_builder.quick_push (CONST1_RTX (BImode));
+ }
+ for (unsigned int i = 0; i < npatterns; ++i)
+ {
+ false_builder.quick_push (CONST_VECTOR_ENCODED_ELT (src, i + npatterns));
+ pred_builder.quick_push (CONST0_RTX (BImode));
+ }
+ expand_operand ops[4];
+ create_output_operand (&ops[0], target, mode);
+ create_input_operand (&ops[1], true_builder.build (), mode);
+ create_input_operand (&ops[2], false_builder.build (), mode);
+ create_input_operand (&ops[3], pred_builder.build (), pred_mode);
+ expand_insn (code_for_vcond_mask (mode, mode), 4, ops);
+ return target;
+}
+
/* Return a register containing CONST_VECTOR SRC, given that SRC has an
SVE data mode and isn't a legitimate constant. Use TARGET for the
result if convenient.
@@ -5300,6 +5350,10 @@ aarch64_expand_sve_const_vector (rtx target, rtx src)
if (GET_MODE_NUNITS (mode).is_constant ())
return NULL_RTX;
+ if (nelts_per_pattern == 2)
+ if (rtx res = aarch64_expand_sve_const_vector_sel (target, src))
+ return res;
+
/* Expand each pattern individually. */
gcc_assert (npatterns > 1);
rtx_vector_builder builder;
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr99246.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr99246.c
new file mode 100644
index 0000000..7f1079c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr99246.c
@@ -0,0 +1,17 @@
+/* { dg-options "-Os" } */
+
+#include <arm_sve.h>
+extern char b[];
+int x;
+void f() {
+ while (x) {
+ x = svaddv(
+ svnot_z(svnot_z(svptrue_pat_b8(SV_VL6),
+ svmov_z(svptrue_pat_b8(SV_VL1),
+ svptrue_pat_b16(SV_VL3))),
+ svptrue_pat_b64(SV_VL2)),
+ svdup_s32(8193));
+ for (int j = x; j; j++)
+ b[j] = 0;
+ }
+}