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][alias-improvements] Fix sixtrack crash


This fixes the crash that occurs during building SPEC2000 sixtrack.
We end up endlessly walking through some irreducible loops.  Fixed
by properly tracking what we visited.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to the 
branch.

Richard.

2009-01-09  Richard Guenther  <rguenther@suse.de>

	* tree-ssa-alias.c (get_continuation_for_phi): Add visited param,
	adjust maybe_skip_until calls.
	(maybe_skip_until): Likewise.  All multiply visited PHI nodes
	finish the walking.
	(walk_non_aliased_vuses): Adjust get_continuation_for_phi calls.
	Free visited bitmap.

	* gcc.dg/tree-ssa/ssa-fre-20.c: New testcase.

Index: gcc/tree-ssa-alias.c
===================================================================
--- gcc/tree-ssa-alias.c	2009-01-09 16:02:48.000000000 +0100
+++ gcc/tree-ssa-alias.c	2009-01-09 15:57:53.000000000 +0100
@@ -488,25 +488,31 @@ stmt_may_clobber_ref_p (gimple stmt, tre
   return false;
 }
 
-static tree get_continuation_for_phi (gimple, tree);
+static tree get_continuation_for_phi (gimple, tree, bitmap *);
 
 /* Walk the virtual use-def chain of VUSE until hitting the virtual operand
    TARGET or a statement clobbering the memory reference REF in which
    case false is returned.  The walk starts with VUSE, one argument of PHI.  */
 
 static bool
-maybe_skip_until (gimple phi, tree target, tree ref, tree vuse)
+maybe_skip_until (gimple phi, tree target, tree ref, tree vuse, bitmap *visited)
 {
+  if (!*visited)
+    *visited = BITMAP_ALLOC (NULL);
+
+  bitmap_set_bit (*visited, SSA_NAME_VERSION (PHI_RESULT (phi)));
+
   /* Walk until we hit the target.  */
   while (vuse != target)
     {
       gimple def_stmt = SSA_NAME_DEF_STMT (vuse);
-      /* The original PHI node ends the walk successfully.  */
+      /* Recurse for PHI nodes.  */
       if (gimple_code (def_stmt) == GIMPLE_PHI)
 	{
-	  if (def_stmt == phi)
+	  /* An already visited PHI node ends the walk successfully.  */
+	  if (bitmap_bit_p (*visited, SSA_NAME_VERSION (PHI_RESULT (def_stmt))))
 	    return true;
-	  vuse = get_continuation_for_phi (def_stmt, ref);
+	  vuse = get_continuation_for_phi (def_stmt, ref, visited);
 	  if (!vuse)
 	    return false;
 	  continue;
@@ -527,7 +533,7 @@ maybe_skip_until (gimple phi, tree targe
    be found.  */
 
 static tree
-get_continuation_for_phi (gimple phi, tree ref)
+get_continuation_for_phi (gimple phi, tree ref, bitmap *visited)
 {
   unsigned nargs = gimple_phi_num_args (phi);
 
@@ -551,14 +557,14 @@ get_continuation_for_phi (gimple phi, tr
 		   && dominated_by_p (CDI_DOMINATORS,
 				      gimple_bb (def1), gimple_bb (def0))))
 	{
-	  if (maybe_skip_until (phi, arg0, ref, arg1))
+	  if (maybe_skip_until (phi, arg0, ref, arg1, visited))
 	    return arg0;
 	}
       else if (gimple_nop_p (def1)
 	       || dominated_by_p (CDI_DOMINATORS,
 				  gimple_bb (def0), gimple_bb (def1)))
 	{
-	  if (maybe_skip_until (phi, arg1, ref, arg0))
+	  if (maybe_skip_until (phi, arg1, ref, arg0, visited))
 	    return arg1;
 	}
     }
@@ -581,28 +587,33 @@ void *
 walk_non_aliased_vuses (tree ref, tree vuse,
 			void *(*walker)(tree, tree, void *), void *data)
 {
+  bitmap visited = NULL;
+  void *res;
+
   do
     {
       gimple def_stmt;
-      void *res;
 
       res = (*walker) (ref, vuse, data);
       if (res)
-	return res;
+	break;
 
       def_stmt = SSA_NAME_DEF_STMT (vuse);
       if (gimple_nop_p (def_stmt))
-	return NULL;
+	break;
       else if (gimple_code (def_stmt) == GIMPLE_PHI)
-	vuse = get_continuation_for_phi (def_stmt, ref);
+	vuse = get_continuation_for_phi (def_stmt, ref, &visited);
       else
 	{
 	  if (stmt_may_clobber_ref_p (def_stmt, ref))
-	    return NULL;
+	    break;
 	  vuse = gimple_vuse (def_stmt);
 	}
     }
   while (vuse);
 
-  return NULL;
+  if (visited)
+    BITMAP_FREE (visited);
+
+  return res;
 }
Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-20.c
===================================================================
*** gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-20.c	(revision 0)
--- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-20.c	(revision 0)
***************
*** 0 ****
--- 1,20 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fdump-tree-optimized" } */
+ 
+ int i, j;
+ int foo(int b)
+ {
+   j = 0;
+   if (b)
+     goto L2;
+ L1:
+   i = i + 1;
+ L2:
+   i = i + 1;
+   if (i == 1)
+     goto L1;
+   return j;
+ }
+ 
+ /* { dg-final { scan-tree-dump "return 0;" "optimized" } } */
+ /* { dg-final { cleanup-tree-dump "optimized" } } */


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