[Bug tree-optimization/23838] [4.1/4.2 Regression] infinite loop in dse

Jeffrey A Law law@redhat.com
Thu Dec 15 02:53:00 GMT 2005


On Tue, 2005-12-13 at 00:23 +0000, pinskia at gcc dot gnu dot org wrote:
> 
> ------- Comment #2 from pinskia at gcc dot gnu dot org  2005-12-13 00:23 -------
> I am going to say this is 4.1 regression as it worked in 4.0.0 when removing
> the -fno-tree-copy-prop option but fails on the mainline and 4.1 branche with
> it.  Somehow or another someone could come up with a testcase which fails also
> without any options which turn off optimizations (it is just harder to come up
> with one).
I just checked in the attached patch to the 4.1 branch.  I'm testing the
same patch for mainline now.

Basically we had a PHI node which both used and defined the same
SSA_NAME (which can only occur at the head of a loop where the
SSA_NAME is an invariant and copies have not been fully propagated).

The safe thing to do is not try and optimize this case.


-------------- next part --------------
	* tree-ssa-dse.c (dse_optimize_stmt): Correctly handle PHI nodes which
	represent a use and definition of the same SSA_NAME.

	* gcc.dg/tree-ssa/ssa-dse-8.c: New test.

Index: tree-ssa-dse.c
===================================================================
*** tree-ssa-dse.c	(revision 108449)
--- tree-ssa-dse.c	(working copy)
*************** dse_optimize_stmt (struct dom_walk_data 
*** 309,314 ****
--- 309,323 ----
  	     && TREE_CODE (use_stmt) == PHI_NODE
  	     && bitmap_bit_p (dse_gd->stores, get_stmt_uid (use_stmt)))
  	{
+ 	  /* A PHI node can both define and use the same SSA_NAME if
+ 	     the PHI is at the top of a loop and the PHI_RESULT is
+ 	     a loop invariant and copies have not been fully propagated.
+ 
+ 	     The safe thing to do is exit assuming no optimization is
+ 	     possible.  */
+ 	  if (SSA_NAME_DEF_STMT (PHI_RESULT (use_stmt)) == use_stmt)
+ 	    return;
+ 
  	  /* Skip past this PHI and loop again in case we had a PHI
  	     chain.  */
  	  if (single_imm_use (PHI_RESULT (use_stmt), &use_p, &use_stmt))
Index: testsuite/gcc.dg/tree-ssa/ssa-dse-8.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/ssa-dse-8.c	(revision 0)
--- testsuite/gcc.dg/tree-ssa/ssa-dse-8.c	(revision 0)
***************
*** 0 ****
--- 1,26 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O2 -fno-tree-dce -fno-tree-ccp -fno-tree-copy-prop -fno-tree-dominator-opts" } */
+ 
+ /* This caused the compiler to enter an infinite loop if copies are not
+    fully propagated.   The options are to disable copy propagation and
+    thus expose the bug.   */
+ 
+ int foo (void);
+ 
+ struct A {
+   struct B {
+     struct B *n;
+   } *p;
+ };
+ 
+ static inline void baz (struct A *a)
+ {
+   a->p = a->p->n;
+ }
+ 
+ void bar (struct A a)
+ {
+   while (foo ())
+     baz (&a);
+   while (foo ());
+ }


More information about the Gcc-patches mailing list