[PATCH] Fix -g ICE from iv increment insertion (PR debug/46885)

Jakub Jelinek jakub@redhat.com
Tue Dec 14 10:49:00 GMT 2010


Hi!

Half a year ago Alex changed canonicalize_loop_ivs (and another place) to
use gsi_last_nondebug_bb instead of gsi_last_bb.  The problem with that
is that in bump_in_latch case create_iv isn't adding stmts before the given
stmt (in which case we really want to insert before last non-debug stmt),
but after the last stmt, and in that case if the bb is non-empty, but
contains only DEBUG stmts, we ICE because gsi will be gsi_end_p and trying
to insert after it in non-emtpy bb is invalid.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2010-12-14  Jakub Jelinek  <jakub@redhat.com>

	PR debug/46885
	* tree-ssa-loop-manip.c (canonicalize_loop_ivs): Use gsi_last_bb
	instead of gsi_last_nondebug_bb if bump_in_latch.

	* gcc.dg/autopar/pr46885.c: New test.

--- gcc/tree-ssa-loop-manip.c.jj	2010-11-19 20:56:54.000000000 +0100
+++ gcc/tree-ssa-loop-manip.c	2010-12-13 16:35:18.000000000 +0100
@@ -1221,7 +1221,10 @@ canonicalize_loop_ivs (struct loop *loop
 	gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts);
     }
 
-  gsi = gsi_last_nondebug_bb (bump_in_latch ? loop->latch : loop->header);
+  if (bump_in_latch)
+    gsi = gsi_last_bb (loop->latch);
+  else
+    gsi = gsi_last_nondebug_bb (loop->header);
   create_iv (build_int_cst_type (type, 0), build_int_cst (type, 1), NULL_TREE,
 	     loop, &gsi, bump_in_latch, &var_before, NULL);
 
--- gcc/testsuite/gcc.dg/autopar/pr46885.c.jj	2010-12-13 16:43:28.000000000 +0100
+++ gcc/testsuite/gcc.dg/autopar/pr46885.c	2010-12-13 16:43:08.000000000 +0100
@@ -0,0 +1,23 @@
+/* PR debug/46885 */
+/* { dg-do compile } */
+/* { dg-options "-O -ftree-parallelize-loops=4 -fcompare-debug -fno-tree-dominator-opts -funswitch-loops" } */
+
+static inline void
+bar (int i)
+{
+  (void) i;
+}
+
+int
+foo (int *begin, int *end)
+{
+  int s = 0;
+  int *i;
+  for (i = begin; i != end; ++i)
+    {
+      bar (0);
+      if (begin)
+	return s;
+    }
+  return 0;
+}

	Jakub



More information about the Gcc-patches mailing list