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]

Re: [PATCH] Fix inconsistent pruning of aliases


On Tue, 20 Nov 2007, Richard Guenther wrote:

> On Tue, 20 Nov 2007, Daniel Berlin wrote:
> 
> > On 11/20/07, Richard Guenther <rguenther@suse.de> wrote:
> > > On Tue, 20 Nov 2007, Daniel Berlin wrote:
> > >
> > > > On 11/20/07, Richard Guenther <rguenther@suse.de> wrote:
> > 
> > > > At this point, you need to recompute aliasing (or move propagation to
> > > > a different point).
> > > > Trying to work around that is not going to work very well, it's not
> > > > what the machinery is meant for.
> > >
> > > Uhm, so we need to re-run may_alias after every copy-propagation?
> > >
> > >  p_2 = p_1
> > >  *p_2;
> > 
> > You at least need to copy the NMT from p_2 to p_1, yes.
> > 
> > You can't add new dereferences without doing *something* to inform the
> > alias machinery that new  dereferences have occurred.
> 
> Ok, so in this case phicprop is broken.  It propagates p_1 in
> 
>  # p_2 = PHI <p_1(2)>
>  *p_2
> 
> but does not merge alias info from p_2.

It actually is cfgcleanup that fails to update points-to information.
But, merge_alias_info does not touch flow-sensitive information at all
(but just verifies it is compatible).  So, what seems to "work" here is
to blindly copy over pointer info from the original pointer in case
we had no information for the new one. ?!

That fixes

int *p;
int inline bar(void) { return 0; }
int foo(int x)
{
  int i;
  int *q;
  if (bar())
    q = &i;
  else
    q = p;
  return *q + *p;
}

which previously after CCP had

<bb 2>:
  D.1549_10 = 0;
  D.1549_2 = 0;
  # VUSE <p_13(D)>
  q_4 = p;
  # VUSE <i_11(D)>
  D.1551_5 = *q_4;
  # VUSE <p_13(D)>
  p.0_6 = p;
  # VUSE <SMT.15_12(D)>
  D.1553_7 = *p.0_6;

(note q_4 and p.0_6 both are equal to p, but one VUSEs i_11 and one 
SMT.15_12).  And after the following patch

<bb 2>:
  D.1549_10 = 0;
  D.1549_2 = 0;
  # VUSE <p_13(D)>
  q_4 = p;
  # VUSE <i_11(D), SMT.15_12(D)>
  D.1551_5 = *q_4;
  # VUSE <p_13(D)>
  p.0_6 = p;
  # VUSE <SMT.15_12(D)>
  D.1553_7 = *p.0_6;

which is conservatively correct at least (it obviously doesn't notice
that p_4 can no longer point to i as that would require re-running PTA).

What am I missing?

Richard.

Index: tree-ssa-copy.c
===================================================================
*** tree-ssa-copy.c	(revision 130328)
--- tree-ssa-copy.c	(working copy)
*************** merge_alias_info (tree orig_name, tree n
*** 277,282 ****
--- 277,292 ----
  	  && new_ptr_info->pt_vars)
  	gcc_assert (bitmap_intersect_p (new_ptr_info->pt_vars,
  					orig_ptr_info->pt_vars));
+ 
+       if ((!new_ptr_info
+ 	   || new_ptr_info->name_mem_tag == NULL_TREE)
+ 	  && orig_ptr_info
+ 	  && orig_ptr_info->name_mem_tag)
+ 	{
+ 	  if (!new_ptr_info)
+ 	    new_ptr_info = get_ptr_info (new_name);
+ 	  memcpy (new_ptr_info, orig_ptr_info, sizeof (struct ptr_info_def));
+ 	}
      }
  }   
  


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