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]Follow-on for aliasing on vector replacements to match original


Diego Novillo <dnovillo@redhat.com> wrote on 05/27/2005 01:14:06 PM:

> On Thu, May 26, 2005 at 07:00:36AM -0500, Keith Besaw wrote:
> 
> > +          /* FIXME, if aliases has just one member mbr which 
satisfies
> > +             get_var_ann (mbr)->mem_tag_kind == TYPE_TAG then should
> > +             p_ann->type_mem_tag be set to mbr (and avoid the call to
> > +             create_memory_tag)?  */
> >
> No.  This would defeat your purpose.  When you call this
> function, you know that all SSA version numbers of 'ptr' will
> only ever point to 'var'.  If you make it share the tag for
> 'var', then you will effectively make it alias all the aliases
> for 'var', which is not what you want.
> 

I wasn't trying to somehow improve the aliasing even though I know that
the vector pointer only points at the array.  I think it's still
necessary to keep the original aliasing.  For example:

int a[100];
int b[100];
int *p;

if (boolexp)
  p = a;
else
  p = b;

tmp = *p + 5;

for (i=0; i<100; ++i)
  a[i] = b[i];

...

tmp2 = *p + 5;

When the for loop is vectorized to something like:

for (i=0; i<100/4; ++i)
  vect_a[i] = vect_b[i]

You need to have the aliasing for the replacement vect_a be
identical to that of the original "a" so that *p is known
to be redefined across the loop.  You don't want the two
references to *p + 5 to be optimized (eg. CSEed).

>From read-arch.c in the SPEC vpr benchmark.

Before Vectorization a loop contains the following statement:

#   TMT.643D.7803_38 = V_MAY_DEF <TMT.643D.7803_26>;
isreadD.4001[iD.4093_444] = 0;

isrreadD.4001 has a single member in its may_aliases list
TMT.643D.7803.  After vectorization, the array element reference
to isread is replaced with an INDIRECT_REF to a pointer to vector.
The version of new_type_alias I've been experimenting with and
which I've attached below assigns the tag TMT.643D.7803 to the
type_mem_tag of the pointer which keeps the aliasing identical.
debug_generic_stmt shows the replacement vectorized statement as:

#   TMT.643D.7803_38 = V_MAY_DEF <TMT.643D.7803_26>;
*vect_pisread.681D.7944_502 = vect_cst_.680D.7943_509;

There are uses of array isread after the vectorized loop which
continue to use the type memory tag which seems perfect.
For example.

#   VUSE <TMT.643D.7803_230>;
D.4379_651 = isreadD.4001[4];

> 
> > +          size_t i;
> > +          for (i = 0; i < VARRAY_ACTIVE_SIZE (aliases); i++)
> > +            add_may_alias (tag, VARRAY_TREE (aliases, i));
> > +        }
> > +    }
> > +
> > +  /* Note, TAG and its set of aliases are not marked for renaming. */
> >
> Move this comment to the start of the function, please.
> 
> Mind line wrapping.  Lines should be less than 80 columns.  The
> rest looks fine.  Will you submit the ivopts bits separately?
> 
> 
> Diego.

I'll move the comment and try to remember to watch line wraps.
When the final version of new_type_alias is accepted I'll submit a
separate one for ivopts.  There are several possibilities that I
need to try.  First to just replace add_type_alias with
new_type_alias.  If that doesn't work because the mark-for-renaming
calls are needed then keep add_type_alias but have it call
new_type_alias followed by the mark-for-renaming calls.  There is
also the question of whether-or-not to keep the current search in
add-type-alias for an existing type tag.  To me that search doesn't
seem quite right, but I suppose I should look into it.

Keith


The following is a version of the patch where if the may_aliases
list of var has a single member which is a type tag then this type
tag is assigned to the type_mem_tag field of the pointer.

Changelog:

      2005-05-27  Keith Besaw  <kbesaw@us.ibm.com>

      * tree-ssa-alias.c (new_type_alias): If the variable
        has a may_aliases list then duplicate it for the
        may_aliases list of the new type tag.

Index: tree-ssa-alias.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/tree-ssa-alias.c,v
retrieving revision 2.92
diff -u -3 -p -r2.92 tree-ssa-alias.c
--- tree-ssa-alias.c    24 May 2005 19:57:52 -0000      2.92
+++ tree-ssa-alias.c    27 May 2005 21:14:01 -0000
@@ -2776,6 +2776,70 @@ found_tag:
 }
 
 
+/* Create a new type tag for PTR.  Construct the may-alias list of this 
type
+   tag so that it has the aliasing of VAR. 
+
+   Note, the set of aliases represented by the new type tag are not 
marked
+   for renaming.  */
+
+void
+new_type_alias (tree ptr, tree var)
+{
+  var_ann_t p_ann = var_ann (ptr);
+  tree tag_type = TREE_TYPE (TREE_TYPE (ptr));
+  var_ann_t v_ann = var_ann (var);
+  tree tag;
+  subvar_t svars;
+
+  gcc_assert (p_ann->type_mem_tag == NULL_TREE);
+  gcc_assert (v_ann->mem_tag_kind == NOT_A_TAG);
+
+  /* Add VAR to the may-alias set of PTR's new type tag.  If VAR has
+     subvars, add the subvars to the tag instead of the actual var.  */
+  if (var_can_have_subvars (var)
+      && (svars = get_subvars_for_var (var)))
+    {
+      subvar_t sv;
+      tag = create_memory_tag (tag_type, true);
+      p_ann->type_mem_tag = tag;
+
+      for (sv = svars; sv; sv = sv->next)
+        add_may_alias (tag, sv->var);
+    }
+  else
+    {
+      /* The following is based on code in add_stmt_operand to ensure 
that the
+         same defs/uses/vdefs/vuses will be found after replacing a 
reference
+         to var (or ARRAY_REF to var) with an INDIRECT_REF to ptr whose 
value
+         is the address of var.  */
+      varray_type aliases = v_ann->may_aliases;
+
+      if ((aliases != NULL)
+          && (VARRAY_ACTIVE_SIZE (aliases) == 1))
+        {
+          tree ali = VARRAY_TREE (aliases, 0);
+          if (get_var_ann (ali)->mem_tag_kind == TYPE_TAG)
+            {
+              p_ann->type_mem_tag = ali;
+              return;
+            }
+        }
+
+      tag = create_memory_tag (tag_type, true);
+      p_ann->type_mem_tag = tag;
+
+      if (aliases == NULL)
+        add_may_alias (tag, var);
+      else
+        {
+          size_t i;
+          for (i = 0; i < VARRAY_ACTIVE_SIZE (aliases); i++)
+            add_may_alias (tag, VARRAY_TREE (aliases, i));
+        }
+    }
+}
+
+
 /* This structure is simply used during pushing fields onto the 
fieldstack
    to track the offset of the field, since bitpos_of_field gives it 
relative
    to its immediate containing type, and we want it relative to the 
ultimate


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