re PR tree-optimization/89247 (ICE in expand_LOOP_VECTORIZED, at internal-fn.c:2409)
authorRichard Biener <rguenther@suse.de>
Fri, 8 Feb 2019 13:21:36 +0000 (13:21 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 8 Feb 2019 13:21:36 +0000 (13:21 +0000)
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.

From-SVN: r268689

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr89247.c [new file with mode: 0644]
gcc/tree-if-conv.c
gcc/tree-if-conv.h

index ef22ae2..a961722 100644 (file)
@@ -1,3 +1,14 @@
+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.
+
 2019-02-08  Ilya Leoshkevich  <iii@linux.ibm.com>
 
        * config/s390/constraints.md (jdd): New constraint.
index 53ad08a..eeb1000 100644 (file)
@@ -1,3 +1,8 @@
+2019-02-08  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/89247
+       * gcc.dg/torture/pr89247.c: New testcase.
+
 2019-02-08  Ilya Leoshkevich  <iii@linux.ibm.com>
 
        * gcc.target/s390/jump-label.c: New test.
diff --git a/gcc/testsuite/gcc.dg/torture/pr89247.c b/gcc/testsuite/gcc.dg/torture/pr89247.c
new file mode 100644 (file)
index 0000000..558e89e
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+
+int *a;
+void b()
+{
+  void *c = &&d;
+  for (;;)
+    d:
+       if (*a)
+         ;
+       else
+         *a = ({ 0 < b; });
+}
index bdd4c2a..cfeaec7 100644 (file)
@@ -119,6 +119,7 @@ along with GCC; see the file COPYING3.  If not see
 #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 loop *loop)
   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 *fun)
   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 *fun)
        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 9e745d1..c136ebb 100644 (file)
@@ -19,6 +19,6 @@ along with GCC; see the file COPYING3.  If not see
 #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  */