re PR tree-optimization/46172 (ICE: in expand_widen_pattern_expr, at optabs.c:522...
authorRichard Guenther <rguenther@suse.de>
Thu, 18 Nov 2010 15:17:37 +0000 (15:17 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 18 Nov 2010 15:17:37 +0000 (15:17 +0000)
2010-11-18  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/46172
* tree-vect-loop-manip.c (remove_dead_stmts_from_loop): New
function.
(slpeel_tree_peel_loop_to_edge): Call it.

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

From-SVN: r166908

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr46172.c [new file with mode: 0644]
gcc/tree-vect-loop-manip.c

index 1fbec11..7aa714c 100644 (file)
@@ -1,3 +1,10 @@
+2010-11-18  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/46172
+       * tree-vect-loop-manip.c (remove_dead_stmts_from_loop): New
+       function.
+       (slpeel_tree_peel_loop_to_edge): Call it.
+
 2010-11-18  Jeff Law  <law@redhat.com>
 
        PR middle-end-optimization/46297
index 3a6e36a..9eace4d 100644 (file)
@@ -1,3 +1,8 @@
+2010-11-18  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/46172
+       * gcc.dg/torture/pr46172.c: New testcase.
+
 2010-11-18  Jeff Law  <law@redhat.com>
 
        PR middle-end-optimization/46297
diff --git a/gcc/testsuite/gcc.dg/torture/pr46172.c b/gcc/testsuite/gcc.dg/torture/pr46172.c
new file mode 100644 (file)
index 0000000..c8d1b47
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fno-tree-dce -ftree-vectorize" } */
+
+extern short X[];
+
+int foo (int len)
+{
+  int i;
+  int s = 0;
+  for (i = 0; i < len; i++)
+    s += X[i] * X[i];
+  return s;
+}
index f006182..eb7eada 100644 (file)
@@ -1107,6 +1107,34 @@ set_prologue_iterations (basic_block bb_before_first_loop,
 }
 
 
+/* Remove dead assignments from loop NEW_LOOP.  */
+
+static void
+remove_dead_stmts_from_loop (struct loop *new_loop)
+{
+  basic_block *bbs = get_loop_body (new_loop);
+  unsigned i;
+  for (i = 0; i < new_loop->num_nodes; ++i)
+    {
+      gimple_stmt_iterator gsi;
+      for (gsi = gsi_start_bb (bbs[i]); !gsi_end_p (gsi);)
+       {
+         gimple stmt = gsi_stmt (gsi);
+         if (is_gimple_assign (stmt)
+             && TREE_CODE (gimple_assign_lhs (stmt)) == SSA_NAME
+             && has_zero_uses (gimple_assign_lhs (stmt)))
+           {
+             gsi_remove (&gsi, true);
+             release_defs (stmt);
+           }
+         else
+           gsi_next (&gsi);
+       }
+    }
+  free (bbs);
+}
+
+
 /* Function slpeel_tree_peel_loop_to_edge.
 
    Peel the first (last) iterations of LOOP into a new prolog (epilog) loop
@@ -1415,6 +1443,13 @@ slpeel_tree_peel_loop_to_edge (struct loop *loop,
   if (update_first_loop_count)
     slpeel_make_loop_iterate_ntimes (first_loop, first_niters);
 
+  /* Remove all pattern statements from the loop copy.  They will confuse
+     the expander if DCE is disabled.
+     ???  The pattern recognizer should be split into an analysis and
+     a transformation phase that is then run only on the loop that is
+     going to be transformed.  */
+  remove_dead_stmts_from_loop (new_loop);
+
   adjust_vec_debug_stmts ();
 
   BITMAP_FREE (definitions);