This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix -ftree-loop-distribution (PR tree-optimization/39007)


Hi,

Attached is a patch to fix an ICE that's triggered by
-ftree-loop-distribution.

Consider the attached testcase.

Recall that -ftree-loop-distribution can convert certain statements to
memset.  If we convert every statement to memset, we have to remove
the loop, update dominator info, and put things back to the SSA form.

Here is the IR right after generating memset but before putting things
back to the SSA form:

<bb 2>:
  if (count_7(D) > 0)
    goto <bb 3>;
  else
    goto <bb 6>;

<bb 3>:
Invalid sum of outgoing probabilities 0.0%
  D.1262_11 = (unsigned int) count_7(D);
  D.1263_3 = D.1262_11 * 4;
  # SMT.9 = VDEF <SMT.9>
  __builtin_memset (p_5(D), 0, D.1263_3);
  D.1264_2 = (unsigned int) count_7(D);
  D.1265_1 = D.1264_2 * 4;
  # SMT.9 = VDEF <SMT.9>
  __builtin_memset (q_6(D), 0, D.1265_1);

<bb 6>:
Invalid sum of incoming frequencies 81, should be 900
  return;

Notice that <bb 6> has two incoming edges, from <bb 2> and <bb3>.
However, the pass calls:

  set_immediate_dominator (CDI_DOMINATORS, <bb 6>, <bb 3>);

This is wrong.  The immediate dominator of <bb 6> is not <bb 3> but
<bb 2> in this case.  This wrong dominator info will later mess up
compute_dominance_frontiers_1 as it relies on accurate
get_immediate_dominator, triggering a segfault.

The patch fixes the problem with:

  set_immediate_dominator (CDI_DOMINATORS, dest,
                           recompute_dominator (CDI_DOMINATORS, dest));

Basic blocks for the loop are removed, so DEST should be the only
basic block we need to update the immediate dominator of.

Tested on x86_64-pc-linux-gnu.  OK to apply?

Kazu Hirata

2009-01-29  Kazu Hirata  <kazu@codesourcery.com>

	PR tree-optimization/39007
	* tree-loop-distribution.c (generate_memset_zero): Use
	POINTER_PLUS_EXPR for a pointer addition.

2009-01-29  Kazu Hirata  <kazu@codesourcery.com>

	PR tree-optimization/39007
	* gcc.dg/tree-ssa/pr39007.c: New.

Index: gcc/testsuite/gcc.dg/tree-ssa/pr39007.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/pr39007.c	(revision 0)
+++ gcc/testsuite/gcc.dg/tree-ssa/pr39007.c	(revision 0)
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-loop-distribution" } */
+
+void
+foo (int *__restrict__ p, int *__restrict__ q, int count)
+{
+  int i;
+  for (i = 0; i < count; i++)
+    {
+      *p++ = 0;
+      *q++ = 0;
+    }
+}
Index: gcc/tree-loop-distribution.c
===================================================================
--- gcc/tree-loop-distribution.c	(revision 143757)
+++ gcc/tree-loop-distribution.c	(working copy)
@@ -439,11 +439,13 @@ generate_builtin (struct loop *loop, bit
       basic_block dest = single_exit (loop)->dest;
       prop_phis (dest);
       make_edge (src, dest, EDGE_FALLTHRU);
-      set_immediate_dominator (CDI_DOMINATORS, dest, src);
       cancel_loop_tree (loop);
 
       for (i = 0; i < nbbs; i++)
 	delete_basic_block (bbs[i]);
+
+      set_immediate_dominator (CDI_DOMINATORS, dest,
+			       recompute_dominator (CDI_DOMINATORS, dest));
     }
 
  end:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]