diff mbox

Fix PR64091

Message ID 56A629CE.1050301@mentor.com
State New
Headers show

Commit Message

Tom de Vries Jan. 25, 2016, 1:57 p.m. UTC
On 27/11/14 15:13, Richard Biener wrote:
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
>
> Richard.
>
> 2014-11-27  Richard Biener  <rguenther@suse.de>
>
> 	PR tree-optimization/64088
> 	* tree-ssa-tail-merge.c (update_debug_stmt): After resetting
> 	the stmt break from the loop over use operands.
>
> 	* gcc.dg/torture/pr64091.c: New testcase.
>
> Index: gcc/tree-ssa-tail-merge.c
> ===================================================================
> --- gcc/tree-ssa-tail-merge.c	(revision 218117)
> +++ gcc/tree-ssa-tail-merge.c	(working copy)
> @@ -1606,9 +1613,7 @@ update_debug_stmt (gimple stmt)
>   {
>     use_operand_p use_p;
>     ssa_op_iter oi;
> -  basic_block bbdef, bbuse;
> -  gimple def_stmt;
> -  tree name;
> +  basic_block bbuse;
>
>     if (!gimple_debug_bind_p (stmt))
>       return;
> @@ -1616,19 +1621,16 @@ update_debug_stmt (gimple stmt)
>     bbuse = gimple_bb (stmt);
>     FOR_EACH_PHI_OR_STMT_USE (use_p, stmt, oi, SSA_OP_USE)
>       {
> -      name = USE_FROM_PTR (use_p);
> -      gcc_assert (TREE_CODE (name) == SSA_NAME);
> -
> -      def_stmt = SSA_NAME_DEF_STMT (name);
> -      gcc_assert (def_stmt != NULL);
> -
> -      bbdef = gimple_bb (def_stmt);
> +      tree name = USE_FROM_PTR (use_p);
> +      gimple def_stmt = SSA_NAME_DEF_STMT (name);
> +      basic_block bbdef = gimple_bb (def_stmt);
>         if (bbdef == NULL || bbuse == bbdef
>   	  || dominated_by_p (CDI_DOMINATORS, bbuse, bbdef))
>   	continue;
>
>         gimple_debug_bind_reset_value (stmt);
>         update_stmt (stmt);
> +      break;
>       }
>   }
>
> Index: gcc/testsuite/gcc.dg/torture/pr64091.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/torture/pr64091.c	(revision 0)
> +++ gcc/testsuite/gcc.dg/torture/pr64091.c	(working copy)
> @@ -0,0 +1,28 @@
> +/* { dg-do compile } */
> +/* { dg-additional-options "-g" } */
> +
> +extern int foo(void);
> +
> +int main(void)
> +{
> +  int i, a, b;
> +
> +  if (foo())
> +    return 0;
> +
> +  for (i = 0, a = 0, b = 0; i < 3; i++, a++)
> +  {
> +    if (foo())
> +      break;
> +
> +    if (b += a)
> +      a = 0;
> +  }
> +
> +  if (!a)
> +    return 2;
> +
> +  b += a;
> +
> +  return 0;
> +}
>

Hi,

the ICE that the patch above fixes does not reproduce on 4.9.

One reason is that an edge_flag EDGE_EXECUTABLE happens to be set, which 
prevents tail-merge from doing a merge.

Another reason is that the use that is added to the free_uses freelist 
during update_stmt happens to be not immediately reused, so the contents 
remains the same.

Using first attached patch, which:
- clears EDGE_EXECUTABLE in tail-merge, and
- clears the contents of a use when adding it to the freelist
we manage to trigger the same problem with 4.9.

Is seems possible to me that the same problem could trigger on 4.9 for a 
different example without the trigger patch.

The second attached patch is a minimal version of the above fix.

OK for 4.9?

Thanks,
- Tom

Comments

Richard Biener Jan. 25, 2016, 2:07 p.m. UTC | #1
On Mon, 25 Jan 2016, Tom de Vries wrote:

> On 27/11/14 15:13, Richard Biener wrote:
> > 
> > Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
> > 
> > Richard.
> > 
> > 2014-11-27  Richard Biener  <rguenther@suse.de>
> > 
> > 	PR tree-optimization/64088
> > 	* tree-ssa-tail-merge.c (update_debug_stmt): After resetting
> > 	the stmt break from the loop over use operands.
> > 
> > 	* gcc.dg/torture/pr64091.c: New testcase.
> > 
> > Index: gcc/tree-ssa-tail-merge.c
> > ===================================================================
> > --- gcc/tree-ssa-tail-merge.c	(revision 218117)
> > +++ gcc/tree-ssa-tail-merge.c	(working copy)
> > @@ -1606,9 +1613,7 @@ update_debug_stmt (gimple stmt)
> >   {
> >     use_operand_p use_p;
> >     ssa_op_iter oi;
> > -  basic_block bbdef, bbuse;
> > -  gimple def_stmt;
> > -  tree name;
> > +  basic_block bbuse;
> > 
> >     if (!gimple_debug_bind_p (stmt))
> >       return;
> > @@ -1616,19 +1621,16 @@ update_debug_stmt (gimple stmt)
> >     bbuse = gimple_bb (stmt);
> >     FOR_EACH_PHI_OR_STMT_USE (use_p, stmt, oi, SSA_OP_USE)
> >       {
> > -      name = USE_FROM_PTR (use_p);
> > -      gcc_assert (TREE_CODE (name) == SSA_NAME);
> > -
> > -      def_stmt = SSA_NAME_DEF_STMT (name);
> > -      gcc_assert (def_stmt != NULL);
> > -
> > -      bbdef = gimple_bb (def_stmt);
> > +      tree name = USE_FROM_PTR (use_p);
> > +      gimple def_stmt = SSA_NAME_DEF_STMT (name);
> > +      basic_block bbdef = gimple_bb (def_stmt);
> >         if (bbdef == NULL || bbuse == bbdef
> >   	  || dominated_by_p (CDI_DOMINATORS, bbuse, bbdef))
> >   	continue;
> > 
> >         gimple_debug_bind_reset_value (stmt);
> >         update_stmt (stmt);
> > +      break;
> >       }
> >   }
> > 
> > Index: gcc/testsuite/gcc.dg/torture/pr64091.c
> > ===================================================================
> > --- gcc/testsuite/gcc.dg/torture/pr64091.c	(revision 0)
> > +++ gcc/testsuite/gcc.dg/torture/pr64091.c	(working copy)
> > @@ -0,0 +1,28 @@
> > +/* { dg-do compile } */
> > +/* { dg-additional-options "-g" } */
> > +
> > +extern int foo(void);
> > +
> > +int main(void)
> > +{
> > +  int i, a, b;
> > +
> > +  if (foo())
> > +    return 0;
> > +
> > +  for (i = 0, a = 0, b = 0; i < 3; i++, a++)
> > +  {
> > +    if (foo())
> > +      break;
> > +
> > +    if (b += a)
> > +      a = 0;
> > +  }
> > +
> > +  if (!a)
> > +    return 2;
> > +
> > +  b += a;
> > +
> > +  return 0;
> > +}
> > 
> 
> Hi,
> 
> the ICE that the patch above fixes does not reproduce on 4.9.
> 
> One reason is that an edge_flag EDGE_EXECUTABLE happens to be set, which
> prevents tail-merge from doing a merge.
> 
> Another reason is that the use that is added to the free_uses freelist during
> update_stmt happens to be not immediately reused, so the contents remains the
> same.
> 
> Using first attached patch, which:
> - clears EDGE_EXECUTABLE in tail-merge, and

this shows a latent issue in tail-merging that it doesn't ignore
edge flags that are "private" (that is, they have random state upon
pass entry).

> - clears the contents of a use when adding it to the freelist
> we manage to trigger the same problem with 4.9.
>
> Is seems possible to me that the same problem could trigger on 4.9 for a
> different example without the trigger patch.
> 
> The second attached patch is a minimal version of the above fix.
> 
> OK for 4.9?

Ok (the minimal fix).

Thanks,
Richard.

> Thanks,
> - Tom
> 
> 
> 
> 
> 
>
diff mbox

Patch

Backport "Fix PR64091"

2016-01-25  Tom de Vries  <tom@codesourcery.com>

	backport from trunk:
	2014-11-27  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/PR64091
	* tree-ssa-tail-merge.c (update_debug_stmt): After resetting
	the stmt break from the loop over use operands.

	* gcc.dg/torture/pr64091.c: New testcase.

---
 gcc/testsuite/gcc.dg/torture/pr64091.c | 28 ++++++++++++++++++++++++++++
 gcc/tree-ssa-tail-merge.c              |  1 +
 2 files changed, 29 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/torture/pr64091.c b/gcc/testsuite/gcc.dg/torture/pr64091.c
new file mode 100644
index 0000000..0cd994a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr64091.c
@@ -0,0 +1,28 @@ 
+/* { dg-do compile } */
+/* { dg-additional-options "-g" } */
+
+extern int foo(void);
+
+int main(void)
+{
+  int i, a, b;
+
+  if (foo())
+    return 0;
+
+  for (i = 0, a = 0, b = 0; i < 3; i++, a++)
+  {
+    if (foo())
+      break;
+
+    if (b += a)
+      a = 0;
+  }
+
+  if (!a)
+    return 2;
+
+  b += a;
+
+  return 0;
+}
diff --git a/gcc/tree-ssa-tail-merge.c b/gcc/tree-ssa-tail-merge.c
index af2641c..b3022ff 100644
--- a/gcc/tree-ssa-tail-merge.c
+++ b/gcc/tree-ssa-tail-merge.c
@@ -1619,6 +1619,7 @@  update_debug_stmt (gimple stmt)
 
       gimple_debug_bind_reset_value (stmt);
       update_stmt (stmt);
+      break;
     }
 }