optabs: Don't use scalar conversions for vectors [PR93843]
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 25 Feb 2020 19:20:58 +0000 (19:20 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Wed, 26 Feb 2020 12:46:59 +0000 (12:46 +0000)
In this PR we had a conversion between two integer vectors that
both had scalar integer modes.  We then tried to implement the
conversion using the scalar optab for those modes, instead of
doing the conversion elementwise.

I wondered about letting through scalar modes for single-element
vectors, but I don't have any evidence that that's useful/necessary,
so it seemed better to keep things simple.

2020-02-26  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
PR middle-end/93843
* optabs-tree.c (supportable_convert_operation): Reject types with
scalar modes.

gcc/testsuite/
PR middle-end/93843
* gcc.dg/vect/pr93843-1.c: New test.
* gcc.dg/vect/pr93843-2.c: Likewise.

gcc/ChangeLog
gcc/optabs-tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/pr93843-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr93843-2.c [new file with mode: 0644]

index 7504b13..c5b1ecc 100644 (file)
@@ -1,3 +1,9 @@
+2020-02-26  Richard Sandiford  <richard.sandiford@arm.com>
+
+       PR middle-end/93843
+       * optabs-tree.c (supportable_convert_operation): Reject types with
+       scalar modes.
+
 2020-02-26  David Malcolm  <dmalcolm@redhat.com>
 
        * Makefile.in (ANALYZER_OBJS): Add analyzer/bar-chart.o.
index 3d829c2..badd30b 100644 (file)
@@ -284,9 +284,14 @@ supportable_convert_operation (enum tree_code code,
   machine_mode m1,m2;
   bool truncp;
 
+  gcc_assert (VECTOR_TYPE_P (vectype_out) && VECTOR_TYPE_P (vectype_in));
+
   m1 = TYPE_MODE (vectype_out);
   m2 = TYPE_MODE (vectype_in);
 
+  if (!VECTOR_MODE_P (m1) || !VECTOR_MODE_P (m2))
+    return false;
+
   /* First check if we can done conversion directly.  */
   if ((code == FIX_TRUNC_EXPR
        && can_fix_p (m1,m2,TYPE_UNSIGNED (vectype_out), &truncp)
index 35715ad..aa5d41e 100644 (file)
@@ -1,3 +1,9 @@
+2020-02-26  Richard Sandiford  <richard.sandiford@arm.com>
+
+       PR middle-end/93843
+       * gcc.dg/vect/pr93843-1.c: New test.
+       * gcc.dg/vect/pr93843-2.c: Likewise.
+
 2020-02-26  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/93820
diff --git a/gcc/testsuite/gcc.dg/vect/pr93843-1.c b/gcc/testsuite/gcc.dg/vect/pr93843-1.c
new file mode 100644 (file)
index 0000000..23a79ca
--- /dev/null
@@ -0,0 +1,21 @@
+char a;
+struct S { short b, c; } d;
+
+__attribute__((noipa)) void
+foo (int x)
+{
+  if (x != 4)
+    __builtin_abort ();
+}
+
+int
+main ()
+{
+  short *g = &d.c, *h = &d.b;
+  char e = 4 - a;
+  int f;
+  *h = *g = e;
+  for (f = 0; f < 2; f++)
+    foo (d.c);
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/vect/pr93843-2.c b/gcc/testsuite/gcc.dg/vect/pr93843-2.c
new file mode 100644 (file)
index 0000000..5fae3e5
--- /dev/null
@@ -0,0 +1,11 @@
+char in[2] = {2, 2};
+short out[2] = {};
+
+int
+main()
+{
+  for (int i = 0; i < 2; ++i)
+    out[i] = in[i];
+  asm("":::"memory");
+  if (out[0] != 2) __builtin_abort();
+}