diff mbox

Fix PR78384: ICE in loop splitting

Message ID alpine.LSU.2.20.1701231430100.31530@wotan.suse.de
State New
Headers show

Commit Message

Michael Matz Jan. 23, 2017, 1:38 p.m. UTC
Hi,

the loop structure in the testcase is funny enough to confuse loop 
splitting (it essentially would have been an irreducable region if it 
weren't for the fact that one entry edge is stopped with a builtin_trap; 
and so it transforms into a strangely rotated loop where latch and header 
aren't at the usual position).  We need to compute the edge staying in the 
loop given the exit edge, which I was doing by looking at predecessor 
edges of the latch, and that wasn't working with the testcase.  Of course 
there's an easier way: it's simply the edge out of exit->src that isn't 
exit itself :)

So, patch fixes the testcase.  Regstrapped on x86-64-linux with all 
languages+Ada, no regressions.  Okay for trunk?


Ciao,
Michael.

	PR tree-optimization/78384
	* tree-ssa-loop-split.c (patch_loop_exit): Use correct edge.

testsuite/
	PR tree-optimization/78384
	* gcc.dg/pr78384.c: New test.

Comments

Richard Biener Jan. 23, 2017, 1:52 p.m. UTC | #1
On Mon, Jan 23, 2017 at 2:38 PM, Michael Matz <matz@suse.de> wrote:
> Hi,
>
> the loop structure in the testcase is funny enough to confuse loop
> splitting (it essentially would have been an irreducable region if it
> weren't for the fact that one entry edge is stopped with a builtin_trap;
> and so it transforms into a strangely rotated loop where latch and header
> aren't at the usual position).  We need to compute the edge staying in the
> loop given the exit edge, which I was doing by looking at predecessor
> edges of the latch, and that wasn't working with the testcase.  Of course
> there's an easier way: it's simply the edge out of exit->src that isn't
> exit itself :)
>
> So, patch fixes the testcase.  Regstrapped on x86-64-linux with all
> languages+Ada, no regressions.  Okay for trunk?

Ok.

Richard.

>
> Ciao,
> Michael.
>
>         PR tree-optimization/78384
>         * tree-ssa-loop-split.c (patch_loop_exit): Use correct edge.
>
> testsuite/
>         PR tree-optimization/78384
>         * gcc.dg/pr78384.c: New test.
>
> diff --git a/gcc/tree-ssa-loop-split.c b/gcc/tree-ssa-loop-split.c
> index 7809db0..f104b26 100644
> --- a/gcc/tree-ssa-loop-split.c
> +++ b/gcc/tree-ssa-loop-split.c
> @@ -159,7 +159,7 @@ patch_loop_exit (struct loop *loop, gcond *guard, tree nextval, tree newbound,
>                              nextval, newbound);
>    update_stmt (stmt);
>
> -  edge stay = single_pred_edge (loop->latch);
> +  edge stay = EDGE_SUCC (exit->src, EDGE_SUCC (exit->src, 0) == exit);
>
>    exit->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
>    stay->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
> diff --git a/gcc/testsuite/gcc.dg/pr78384.c b/gcc/testsuite/gcc.dg/pr78384.c
> new file mode 100644
> index 0000000..d93437d
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr78384.c
> @@ -0,0 +1,25 @@
> +/* PR tree-optimization/78384
> +   { dg-do compile }
> +   { dg-options "-O3 -w -fsplit-loops" } */
> +void
> +a2 (int wv, int yg, int r9)
> +{
> +  while (wv < 1)
> +    {
> +      int vn = r9 % 0;
> +
> +      while (yg < 1)
> +        {
> +          int lz;
> +
> +          for (r9 = 0; r9 < 17; ++r9)
> +            {
> +            }
> +
> + it:
> +          lz = (yg++ >= 0) ? 2 : 0;
> +          wv = vn < lz;
> +        }
> +    }
> +  goto it;
> +}
diff mbox

Patch

diff --git a/gcc/tree-ssa-loop-split.c b/gcc/tree-ssa-loop-split.c
index 7809db0..f104b26 100644
--- a/gcc/tree-ssa-loop-split.c
+++ b/gcc/tree-ssa-loop-split.c
@@ -159,7 +159,7 @@  patch_loop_exit (struct loop *loop, gcond *guard, tree nextval, tree newbound,
 			     nextval, newbound);
   update_stmt (stmt);
 
-  edge stay = single_pred_edge (loop->latch);
+  edge stay = EDGE_SUCC (exit->src, EDGE_SUCC (exit->src, 0) == exit);
 
   exit->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
   stay->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
diff --git a/gcc/testsuite/gcc.dg/pr78384.c b/gcc/testsuite/gcc.dg/pr78384.c
new file mode 100644
index 0000000..d93437d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr78384.c
@@ -0,0 +1,25 @@ 
+/* PR tree-optimization/78384
+   { dg-do compile }
+   { dg-options "-O3 -w -fsplit-loops" } */
+void
+a2 (int wv, int yg, int r9)
+{
+  while (wv < 1)
+    {
+      int vn = r9 % 0;
+
+      while (yg < 1)
+        {
+          int lz;
+
+          for (r9 = 0; r9 < 17; ++r9)
+            {
+            }
+
+ it:
+          lz = (yg++ >= 0) ? 2 : 0;
+          wv = vn < lz;
+        }
+    }
+  goto it;
+}