This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR46398


When inserting an FRE pass in early optimizations we miscompile the
C++ frontend because we think that SCCs with a single member never
needs iterating.  This is not true as with self-referential PHI
nodes like a_1 = PHI <0, 1, a_1> we end up inserting expressions
with VN_TOP into the expression hash table which then leads us to
false equivalences when processing other SCCs.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2010-11-10  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/46398
	* tree-ssa-sccvn.c (process_scc): Iterate for all PHIs.

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

Index: gcc/tree-ssa-sccvn.c
===================================================================
*** gcc/tree-ssa-sccvn.c	(revision 166491)
--- gcc/tree-ssa-sccvn.c	(working copy)
*************** process_scc (VEC (tree, heap) *scc)
*** 3108,3116 ****
    if (VEC_length (tree, scc) == 1)
      {
        tree use = VEC_index (tree, scc, 0);
!       if (!VN_INFO (use)->use_processed)
! 	visit_use (use);
!       return;
      }
  
    /* Iterate over the SCC with the optimistic table until it stops
--- 3108,3127 ----
    if (VEC_length (tree, scc) == 1)
      {
        tree use = VEC_index (tree, scc, 0);
!       if (VN_INFO (use)->use_processed)
! 	return;
!       /* We need to make sure it doesn't form a cycle itself, which can
! 	 happen for self-referential PHI nodes.  In that case we would
! 	 end up inserting an expression with VN_TOP operands into the
! 	 valid table which makes us derive bogus equivalences later.
! 	 The cheapest way to check this is to assume it for all PHI nodes.  */
!       if (gimple_code (SSA_NAME_DEF_STMT (use)) == GIMPLE_PHI)
! 	/* Fallthru to iteration.  */ ;
!       else
! 	{
! 	  visit_use (use);
! 	  return;
! 	}
      }
  
    /* Iterate over the SCC with the optimistic table until it stops
Index: gcc/testsuite/gcc.dg/torture/pr46398.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr46398.c	(revision 0)
--- gcc/testsuite/gcc.dg/torture/pr46398.c	(revision 0)
***************
*** 0 ****
--- 1,24 ----
+ /* { dg-do run } */
+ 
+ int __attribute__((noinline))
+ test (int token)
+ {
+   int done = 0;
+   int virtual_p = 0;
+   while (!done)
+     {
+       if (token == 42)
+ 	virtual_p = 1;
+       else
+ 	done = 1;
+     }
+   return virtual_p;
+ }
+ extern void abort (void);
+ int
+ main()
+ {
+   if (test (0) != 0)
+     abort ();
+   return 0;
+ }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]