public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-8722] tree-optimization/100778 - fix placement of trapping vectorized ops
@ 2021-07-13 10:59 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-07-13 10:59 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f32145c27eec468247353b59ec5f62fcba3ae2c7

commit r11-8722-gf32145c27eec468247353b59ec5f62fcba3ae2c7
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Jul 1 10:35:38 2021 +0200

    tree-optimization/100778 - fix placement of trapping vectorized ops
    
    This avoids placing possibly trapping vectorized operations where
    the corresponding scalar operation was possibly not executed.
    
    2021-01-07  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/100778
            * tree-vect-slp.c (vect_schedule_slp_node): Do not place trapping
            vectorized ops ahead of their scalar BB.
    
            * gcc.dg/torture/pr100778.c: New testcase.
    
    (cherry picked from commit a3aaba68405751bae3f630669515b7ecdf77efa6)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr100778.c | 31 +++++++++++++++++++++++++++++++
 gcc/tree-vect-slp.c                     | 15 +++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/torture/pr100778.c b/gcc/testsuite/gcc.dg/torture/pr100778.c
new file mode 100644
index 00000000000..7997f2f2bcd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr100778.c
@@ -0,0 +1,31 @@
+/* { dg-do run { target *-*-*gnu* } } */
+/* { dg-additional-options "-fno-tree-sink -fno-math-errno -ftree-vectorize -D_GNU_SOURCE" } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#include <fenv.h>
+
+double a[2];
+void __attribute__((noipa)) foo ()
+{
+  double x = a[0];
+  double y = a[1];
+  double norm = __builtin_sqrt (x*x + y*y);
+  if (norm > 1.)
+    {
+      x = x / norm;
+      y = y / norm;
+    }
+  a[0] = x;
+  a[1] = y;
+}
+
+int main()
+{
+  feenableexcept (FE_INVALID);
+  a[0] = 0.;
+  a[1] = 0.;
+  foo ();
+  if (a[0] != 0. || a[1] != 0.)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index d16071697c3..ffecc9a7cd3 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -6288,6 +6288,21 @@ vect_schedule_slp_node (vec_info *vinfo,
 	  gcc_assert (seen_vector_def);
 	  si = gsi_after_labels (as_a <bb_vec_info> (vinfo)->bbs[0]);
 	}
+      else if (is_a <bb_vec_info> (vinfo)
+	       && gimple_bb (last_stmt) != gimple_bb (stmt_info->stmt)
+	       && gimple_could_trap_p (stmt_info->stmt))
+	{
+	  /* We've constrained possibly trapping operations to all come
+	     from the same basic-block, if vectorized defs would allow earlier
+	     scheduling still force vectorized stmts to the original block.
+	     This is only necessary for BB vectorization since for loop vect
+	     all operations are in a single BB and scalar stmt based
+	     placement doesn't play well with epilogue vectorization.  */
+	  gcc_assert (dominated_by_p (CDI_DOMINATORS,
+				      gimple_bb (stmt_info->stmt),
+				      gimple_bb (last_stmt)));
+	  si = gsi_after_labels (gimple_bb (stmt_info->stmt));
+	}
       else if (is_a <gphi *> (last_stmt))
 	si = gsi_after_labels (gimple_bb (last_stmt));
       else


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-13 10:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-13 10:59 [gcc r11-8722] tree-optimization/100778 - fix placement of trapping vectorized ops Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).