The following fixes SLP vectorization to properly consider
calls like lrint demoting on ilp32 targets.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2019-04-08  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/90006
        * tree-vect-data-refs.c (vect_get_smallest_scalar_type): Handle
        calls like lrint.

        * gcc.dg/vect/bb-slp-pr90006.c: New testcase.

Index: gcc/tree-vect-data-refs.c
===================================================================
--- gcc/tree-vect-data-refs.c   (revision 270202)
+++ gcc/tree-vect-data-refs.c   (working copy)
@@ -144,6 +144,15 @@ vect_get_smallest_scalar_type (gimple *s
       if (rhs < lhs)
         scalar_type = rhs_type;
     }
+  else if (is_gimple_call (stmt)
+          && gimple_call_num_args (stmt) > 0)
+    {
+      tree rhs_type = TREE_TYPE (gimple_call_arg (stmt, 0));
+
+      rhs = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (rhs_type));
+      if (rhs < lhs)
+        scalar_type = rhs_type;
+    }
 
   *lhs_size_unit = lhs;
   *rhs_size_unit = rhs;
Index: gcc/testsuite/gcc.dg/vect/bb-slp-pr90006.c
===================================================================
--- gcc/testsuite/gcc.dg/vect/bb-slp-pr90006.c  (nonexistent)
+++ gcc/testsuite/gcc.dg/vect/bb-slp-pr90006.c  (working copy)
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fno-math-errno" } */
+/* { dg-additional-options "-march=x86-64" { target x86_64-*-* i?86-*-* } } */
+
+long int lrint(double x);
+
+int a, b;
+union c {
+    int d;
+};
+
+int e()
+{
+  int f, g, h;
+  long i, j, k;
+  double l, m = b = lrint(0.3127);
+  a = b >> 16 >> 8 & 255;
+  ((union c *)e)->d = a;
+  k = m;
+  h = k >> 16 >> 8 & 255;
+  ((union c *)(e + 4))->d = h;
+  j = lrint(l);
+  g = j >> 16 >> 8 & 255;
+  ((union c *)(e + 8))->d = g;
+  i = lrint(0.292);
+  f = i >> 16 >> 8 & 255;
+  ((union c *)(e + 12))->d = f;
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump "basic block vectorized" "slp2" { target { { 
x86_64-*-* i?86-*-* } && ilp32 } } } } */

Reply via email to