diff mbox

Fix PR57122, bug in split_edge

Message ID alpine.LNX.2.00.1304301408160.24881@zhemvz.fhfr.qr
State New
Headers show

Commit Message

Richard Biener April 30, 2013, 12:09 p.m. UTC
The following fixes PR57122 where splitting an edge from the
loop latch is wrongly detected as latch-edge split (happens
in case an irreducible region is inside the loop).

Bootstrap and regtest pending on x86_64-unknown-linux-gnu.

Richard.

2013-04-30  Richard Biener  <rguenther@suse.de>

	PR middle-end/57122
	* cfghooks.c (split_edge): Properly check for the loop
	latch edge.

	* gcc.dg/torture/pr57122.c: New testcase.
diff mbox

Patch

Index: gcc/cfghooks.c
===================================================================
--- gcc/cfghooks.c	(revision 198441)
+++ gcc/cfghooks.c	(working copy)
@@ -662,7 +662,9 @@  split_edge (edge e)
       loop = find_common_loop (src->loop_father, dest->loop_father);
       add_bb_to_loop (ret, loop);
 
-      if (loop->latch == src)
+      /* If we split the latch edge of loop adjust the latch block.  */
+      if (loop->latch == src
+	  && loop->header == dest)
 	loop->latch = ret;
     }
 
Index: gcc/testsuite/gcc.dg/torture/pr57122.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr57122.c	(revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr57122.c	(working copy)
@@ -0,0 +1,27 @@ 
+/* { dg-do compile } */
+
+unsigned a;
+int b, c;
+
+void f(void)
+{
+  if(a)
+    {
+      for(a = 0; a < 2; a++)
+	a /= 7;
+
+      for(;; a++)
+	{
+	  if(a)
+	    lbl1:
+		b++;
+
+	  if(c)
+	    goto lbl1;
+lbl2:
+	  ;
+	}
+    }
+
+  goto lbl2;
+}