[PATCH] middle-end/94301 - map V1x to x when the vector mode is not available

Richard Biener rguenther@suse.de
Tue Sep 1 09:50:32 GMT 2020


This maps single-element vectors to the component mode when the
single-element vector mode is not available.  This is what happens
for integer element modes already via mapping to a same-sized
scalar mode (which also covers multi-element vectors).

This avoids ICEing when expanding bit-inserts of single-element
vectors.  It also changes the ABI on targets where this makes
a difference from stack-passing to passing according to the
component mode [on x86 where I checked].

Actually aarch64 and s390 already define V1DF and s390 also V1SF
(and even V1TF).  aarch64 also has V1x{D,S}F, whatever that is.

While IMHO it makes very much sense to map V1{S,D,T}F types
to {S,D,T}Fmode if there's no special vector mode for it the
question is whether we can make this "change" for the sake
of the ABIs?  The alternative is to make vector lowering
adjust this, inserting V_C_Es for example.

So - any comments?  There seems to be some fallout in
build_vector_type_for_mode during bootstrap I have to address
anyway.

Thanks,
Richard.

2020-09-01  Richard Biener  <rguenther@suse.de>

	PR middle-end/94301
	* stor-layout.c (mode_for_vector): For single-element
	vectors map to the component mode.

	* gcc.dg/pr94301-1.c: New testcase.
---
 gcc/stor-layout.c                |  4 ++++
 gcc/testsuite/gcc.dg/pr94301-1.c | 18 ++++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/pr94301-1.c

diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index bde6fa22b58..964152c9180 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -512,6 +512,10 @@ mode_for_vector (scalar_mode innermode, poly_uint64 nunits)
 	return mode;
     }
 
+  /* For single-element vectors, map it to the component mode.  */
+  if (known_eq (nunits, 1u))
+    return innermode;
+
   return opt_machine_mode ();
 }
 
diff --git a/gcc/testsuite/gcc.dg/pr94301-1.c b/gcc/testsuite/gcc.dg/pr94301-1.c
new file mode 100644
index 00000000000..67177951487
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr94301-1.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple -O -w -Wno-psabi" } */
+
+typedef double v1df __attribute__((vector_size(sizeof (double))));
+typedef double v2df __attribute__((vector_size(2 * sizeof (double))));
+typedef long long v2di __attribute__((vector_size(2 * sizeof (double))));
+
+v2df __GIMPLE(ssa) foo (v1df x, v1df z)
+{
+  v2df y;
+
+  __BB(2):
+   y_2 = _Literal (v2df) { x_1(D), _Literal (v1df) { 0.0 } };
+  y_3 = _Literal (v2df) { z_4(D), _Literal (v1df) { 0.0 } };
+  y_5 = __VEC_PERM (y_2, y_3, _Literal (v2di) { 0ll, 2ll });
+  y_6 = __VEC_PERM (y_5, y_5, _Literal (v2di) { 0ll, 0ll });
+  return y_6;
+}
-- 
2.26.2


More information about the Gcc-patches mailing list