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][4.4?] Fix one corner case in SCCVN


SCCVN isn't able to lookup references if the oracle walk ended up
with a default-def VOP (it also doesn't do lookups during the walk,
but fixing that is more invasive).  The trick for this one is to
just ignore default defs for value-numbering.  This should save
both memory and compile-time while doing a little more CSE, like
for the testcase in PR38207.

Bootstrapped and tested on x86_64-unknown-linux-gnu.  I'll
SPEC-bench this to see if it is worthwhile for 4.4, otherwise I'll
just install it on the alias-improvements branch where it fixes
a bunch of regressions.

Richard.

2008-11-22  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/38207
	* tree-ssa-sccvn.c (valueize_vuses): Remove default definitions.
	(vn_reference_lookup_pieces): Accept GIMPLE_NOP as result of
	walking.
	(vn_reference_lookup): Likewise.

	* gcc.dg/tree-ssa/ssa-fre-18.c: New testcase.

Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-18.c
===================================================================
*** gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-18.c	(revision 0)
--- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-18.c	(revision 0)
***************
*** 0 ****
--- 1,28 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fdump-tree-fre" } */
+ 
+ struct a
+ {
+   union
+   {
+     int a;
+     int b;
+   };
+   union
+   {
+     int c;
+     int d;
+   };
+ };
+ 
+ int f(struct a *c)
+ {
+   int d = c->a;
+   c->c = 1;
+   return c->a + d;
+ }
+ 
+ /* We should have CSEd the load from c->a.  */
+ 
+ /* { dg-final { scan-tree-dump-times "c_.*\\\.a" 1 "fre" } } */
+ /* { dg-final { cleanup-tree-dump "fre" } } */
Index: gcc/tree-ssa-sccvn.c
===================================================================
*** gcc/tree-ssa-sccvn.c	(revision 142122)
--- gcc/tree-ssa-sccvn.c	(working copy)
*************** valueize_vuses (VEC (tree, gc) *orig)
*** 885,901 ****
  {
    bool made_replacement = false;
    tree vuse;
!   int i;
  
!   for (i = 0; VEC_iterate (tree, orig, i, vuse); i++)
      {
        if (vuse != SSA_VAL (vuse))
  	{
  	  made_replacement = true;
! 	  VEC_replace (tree, orig, i, SSA_VAL (vuse));
  	}
      }
  
    if (made_replacement && VEC_length (tree, orig) > 1)
      sort_vuses (orig);
  
--- 885,908 ----
  {
    bool made_replacement = false;
    tree vuse;
!   unsigned i, j;
  
!   for (i = 0, j = 0; VEC_iterate (tree, orig, i, vuse); i++, j++)
      {
        if (vuse != SSA_VAL (vuse))
  	{
  	  made_replacement = true;
! 	  vuse = SSA_VAL (vuse);
  	}
+       VEC_replace (tree, orig, j, vuse);
+       /* Remove default definitions.  */
+       if (SSA_NAME_IS_DEFAULT_DEF (vuse))
+ 	j--;
      }
  
+   if (j < VEC_length (tree, orig))
+     VEC_truncate (tree, orig, j);
+ 
    if (made_replacement && VEC_length (tree, orig) > 1)
      sort_vuses (orig);
  
*************** vn_reference_lookup_pieces (VEC (tree, g
*** 1007,1013 ****
        gimple def_stmt;
        if (ref
  	  && (def_stmt = get_def_ref_stmt_vuses (ref, vr1.vuses))
! 	  && is_gimple_assign (def_stmt))
  	{
  	  /* We are now at an aliasing definition for the vuses we want to
  	     look up.  Re-do the lookup with the vdefs for this stmt.  */
--- 1014,1021 ----
        gimple def_stmt;
        if (ref
  	  && (def_stmt = get_def_ref_stmt_vuses (ref, vr1.vuses))
! 	  && (is_gimple_assign (def_stmt)
! 	      || gimple_nop_p (def_stmt)))
  	{
  	  /* We are now at an aliasing definition for the vuses we want to
  	     look up.  Re-do the lookup with the vdefs for this stmt.  */
*************** vn_reference_lookup (tree op, VEC (tree,
*** 1049,1055 ****
        && vr1.vuses
        && VEC_length (tree, vr1.vuses) >= 1
        && (def_stmt = get_def_ref_stmt_vuses (op, vr1.vuses))
!       && is_gimple_assign (def_stmt))
      {
        /* We are now at an aliasing definition for the vuses we want to
  	 look up.  Re-do the lookup with the vdefs for this stmt.  */
--- 1057,1064 ----
        && vr1.vuses
        && VEC_length (tree, vr1.vuses) >= 1
        && (def_stmt = get_def_ref_stmt_vuses (op, vr1.vuses))
!       && (is_gimple_assign (def_stmt)
! 	  || gimple_nop_p (def_stmt)))
      {
        /* We are now at an aliasing definition for the vuses we want to
  	 look up.  Re-do the lookup with the vdefs for this stmt.  */


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