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 7504b13022263110fc505664626f1a7dad8eba28..c5b1eccb7d6c4f9b285fb076d1a5ddf3534151a4 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 3d829c27826a8bcefe3c213736af45e6ebaccc83..badd30bfda8dcf385a7c05f31ccba4834dabc825 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 35715adbe5206708df210594f2b5ea1487abab8e..aa5d41e5559307a8c348b7d081a10414f1f8111f 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();
+}