diff mbox series

Fix PR89247

Message ID alpine.LSU.2.20.1902081347430.23386@zhemvz.fhfr.qr
State New
Headers show
Series Fix PR89247 | expand

Commit Message

Richard Biener Feb. 8, 2019, 12:48 p.m. UTC
The following fixes LOOP_VECTORIZED IFNs made useless by CFG cleanup
after if-conversion by re-verifying the mentioned loops still exist.

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

Richard.

2019-02-08  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/89247
	* tree-if-conv.c: Include tree-cfgcleanup.h.
	(version_loop_for_if_conversion): Record LOOP_VECTORIZED call.
	(tree_if_conversion): Pass through predicate vector.
	(pass_if_conversion::execute): Do CFG cleanup and SSA update
	inline, see if any if-converted loops we refrece in
	LOOP_VECTORIZED calls vanished and fixup.
	* tree-if-conv.h (tree_if_conversion): Adjust prototype.

	* gcc.dg/torture/pr89247.c: New testcase.

Comments

H.J. Lu Feb. 9, 2019, 2:46 p.m. UTC | #1
On Fri, Feb 8, 2019 at 4:49 AM Richard Biener <rguenther@suse.de> wrote:
>
>
> The following fixes LOOP_VECTORIZED IFNs made useless by CFG cleanup
> after if-conversion by re-verifying the mentioned loops still exist.
>
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
>
> Richard.
>
> 2019-02-08  Richard Biener  <rguenther@suse.de>
>
>         PR tree-optimization/89247
>         * tree-if-conv.c: Include tree-cfgcleanup.h.
>         (version_loop_for_if_conversion): Record LOOP_VECTORIZED call.
>         (tree_if_conversion): Pass through predicate vector.
>         (pass_if_conversion::execute): Do CFG cleanup and SSA update
>         inline, see if any if-converted loops we refrece in
>         LOOP_VECTORIZED calls vanished and fixup.
>         * tree-if-conv.h (tree_if_conversion): Adjust prototype.
>

This caused:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89268
diff mbox series

Patch

Index: gcc/tree-if-conv.c
===================================================================
--- gcc/tree-if-conv.c	(revision 268668)
+++ gcc/tree-if-conv.c	(working copy)
@@ -119,6 +119,7 @@  along with GCC; see the file COPYING3.
 #include "internal-fn.h"
 #include "fold-const.h"
 #include "tree-ssa-sccvn.h"
+#include "tree-cfgcleanup.h"
 
 /* Only handle PHIs with no more arguments unless we are asked to by
    simd pragma.  */
@@ -2719,7 +2720,7 @@  combine_blocks (struct loop *loop)
    consistent after the condition is folded in the vectorizer.  */
 
 static struct loop *
-version_loop_for_if_conversion (struct loop *loop)
+version_loop_for_if_conversion (struct loop *loop, vec<gimple *> *preds)
 {
   basic_block cond_bb;
   tree cond = make_ssa_name (boolean_type_node);
@@ -2759,6 +2760,7 @@  version_loop_for_if_conversion (struct l
   new_loop->force_vectorize = false;
   gsi = gsi_last_bb (cond_bb);
   gimple_call_set_arg (g, 1, build_int_cst (integer_type_node, new_loop->num));
+  preds->safe_push (g);
   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
   update_ssa (TODO_update_ssa);
   return new_loop;
@@ -2979,7 +2981,7 @@  ifcvt_local_dce (basic_block bb)
    changed.  */
 
 unsigned int
-tree_if_conversion (struct loop *loop)
+tree_if_conversion (struct loop *loop, vec<gimple *> *preds)
 {
   unsigned int todo = 0;
   bool aggressive_if_conv;
@@ -3027,7 +3029,7 @@  tree_if_conversion (struct loop *loop)
       struct loop *vloop
 	= (versionable_outer_loop_p (loop_outer (loop))
 	   ? loop_outer (loop) : loop);
-      struct loop *nloop = version_loop_for_if_conversion (vloop);
+      struct loop *nloop = version_loop_for_if_conversion (vloop, preds);
       if (nloop == NULL)
 	goto cleanup;
       if (vloop != loop)
@@ -3139,11 +3141,12 @@  pass_if_conversion::execute (function *f
   if (number_of_loops (fun) <= 1)
     return 0;
 
+  auto_vec<gimple *> preds;
   FOR_EACH_LOOP (loop, 0)
     if (flag_tree_loop_if_convert == 1
 	|| ((flag_tree_loop_vectorize || loop->force_vectorize)
 	    && !loop->dont_vectorize))
-      todo |= tree_if_conversion (loop);
+      todo |= tree_if_conversion (loop, &preds);
 
   if (todo)
     {
@@ -3158,7 +3161,30 @@  pass_if_conversion::execute (function *f
 	gcc_assert (!bb->aux);
     }
 
-  return todo;
+  /* Perform IL update now, it might elide some loops.  */
+  if (todo & TODO_cleanup_cfg)
+    {
+      cleanup_tree_cfg ();
+      if (need_ssa_update_p (fun))
+	todo |= TODO_update_ssa;
+    }
+  if (todo & TODO_update_ssa_any)
+    update_ssa (todo & TODO_update_ssa_any);
+
+  /* If if-conversion elided the loop fall back to the original one.  */
+  for (unsigned i = 0; i < preds.length (); ++i)
+    {
+      gimple *g = preds[i];
+      unsigned ifcvt_loop = tree_to_uhwi (gimple_call_arg (g, 0));
+      if (!get_loop (fun, ifcvt_loop))
+	{
+	  if (dump_file)
+	    fprintf (dump_file, "If-converted loop vanished\n");
+	  fold_loop_internal_call (g, boolean_false_node);
+	}
+    }
+
+  return 0;
 }
 
 } // anon namespace
Index: gcc/tree-if-conv.h
===================================================================
--- gcc/tree-if-conv.h	(revision 268668)
+++ gcc/tree-if-conv.h	(working copy)
@@ -19,6 +19,6 @@  along with GCC; see the file COPYING3.
 #ifndef GCC_TREE_IF_CONV_H
 #define GCC_TREE_IF_CONV_H
 
-unsigned int tree_if_conversion (struct loop *);
+unsigned int tree_if_conversion (struct loop *, vec<gimple *> * = NULL);
 
 #endif  /* GCC_TREE_IF_CONV_H  */
Index: gcc/testsuite/gcc.dg/torture/pr89247.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr89247.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/torture/pr89247.c	(working copy)
@@ -0,0 +1,13 @@ 
+/* { dg-do compile } */
+
+int *a;
+void b()
+{
+  void *c = &&d;
+  for (;;)
+    d:
+	if (*a)
+	  ;
+	else
+	  *a = ({ 0 < b; });
+}