]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/100778 - avoid cross-BB vectorization of trapping op
authorRichard Biener <rguenther@suse.de>
Fri, 28 May 2021 12:26:06 +0000 (14:26 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 13 Jul 2021 09:45:42 +0000 (11:45 +0200)
This avoids vectorizing a possibly trapping operation when lanes
are handled in different BBs.  I spotted this when working on the
originally reported issue in PR100778.

2021-05-28  Richard Biener  <rguenther@suse.de>

PR tree-optimization/100778
* tree-vect-slp.c (vect_build_slp_tree_1): Prevent possibly
trapping ops in different BBs.

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

(cherry picked from commit f7a07f5a5d8065e7f11133dd1f4ad3510ab2195b)

gcc/testsuite/gcc.dg/vect/bb-slp-pr100778-1.c [new file with mode: 0644]
gcc/tree-vect-slp.c

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr100778-1.c b/gcc/testsuite/gcc.dg/vect/bb-slp-pr100778-1.c
new file mode 100644 (file)
index 0000000..9f8b7ee
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_double } */
+
+double foo (int x, double *p)
+{
+  double res = p[0] + p[1];
+  double tem = p[0] / x;
+  if (x)
+    {
+      p[0] = tem;
+      p[1] /= x;
+    }
+  return res + tem;
+}
+
+/* We may not SLP vectorize the FP division because it can trap and it
+   is distributed between two basic-blocks.  */
+/* { dg-final { scan-tree-dump "Build SLP failed: different BB for PHI or possibly trapping operation in _\[0-9\]+ = _\[0-9\]+ / _\[0-9\]+;" "slp2" } } */
index a40b2f06a5f58b5d3b0dd3474d3faeb435d5a706..d16071697c3d7ad555f9fc63ca1636b3f7fc4acc 100644 (file)
@@ -1199,14 +1199,14 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
                }
            }
 
-         if (phi_p
+         if ((phi_p || gimple_could_trap_p (stmt_info->stmt))
              && (gimple_bb (first_stmt_info->stmt)
                  != gimple_bb (stmt_info->stmt)))
            {
              if (dump_enabled_p ())
                dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
                                 "Build SLP failed: different BB for PHI "
-                                "in %G", stmt);
+                                "or possibly trapping operation in %G", stmt);
              /* Mismatch.  */
              continue;
            }