[PATCH] Fix CDDCE miscompilation (PR tree-optimization/55018)

Steven Bosscher stevenb.gcc@gmail.com
Mon Oct 22 21:19:00 GMT 2012


On Mon, Oct 22, 2012 at 10:39 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> dominance.c doesn't use cfgloop.h (can it?  Isn't it used before loops are
> computed, perhaps after loops destroyed, etc.), so there is no guarantee
> that loop->latch of endless loop will have the fake edge added and no other
> bb before it.  As 7 and 8 are bigger than 4 or 6, the above loop
> starts with bb 8, finds that its predecessor has already been searched and
> stops there, similarly for 7, then goes on with 6 with another fake edge to
> exit.

At least it looks like some of the cfganal DFS code could be used in
dominance.c. I will have a look.

A hack like the following should result in no fake edges for bb7 and bb8.

Ciao!
Steven


Index: dominance.c
===================================================================
--- dominance.c	(revision 192517)
+++ dominance.c	(working copy)
@@ -353,12 +353,15 @@
 	 pretend that there is an edge to the exit block.  In the second
 	 case, we wind up with a forest.  We need to process all noreturn
 	 blocks before we know if we've got any infinite loops.  */
-
+      int *revcfg_postorder = XNEWVEC (int, n_basic_blocks);
+      int n = inverted_post_order_compute (revcfg_postorder);
+      unsigned int i = (unsigned) n;
       basic_block b;
       bool saw_unconnected = false;

-      FOR_EACH_BB_REVERSE (b)
+      while (i)
 	{
+	  basic_block b = revcfg_postorder[--i];
 	  if (EDGE_COUNT (b->succs) > 0)
 	    {
 	      if (di->dfs_order[b->index] == 0)
@@ -375,8 +378,10 @@

       if (saw_unconnected)
 	{
-	  FOR_EACH_BB_REVERSE (b)
+	  i = n;
+	  while (i)
 	    {
+	      basic_block b = revcfg_postorder[--i];
 	      if (di->dfs_order[b->index])
 		continue;
 	      bitmap_set_bit (di->fake_exit_edge, b->index);



More information about the Gcc-patches mailing list