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] Fold constants in vectorizer


Hello,

> Zdenek Dvorak wrote on 11/10/06 11:46:
> 
> >	* tree-vect-transform.c (vect_generate_tmps_on_preheader): Fold the
> >	emited expressions.
> >
> OK.

before commiting this patch, I have noticed that it actually causes
regression of one of the vectorizer tests that I overlooked before.  The
problem is in new_type_alias -- we use the position obtained from
get_ref_base_and_extent of EXPR to find subvars of the VAR variable.
This however is wrong, since e.g. VAR may be a variable of type

struct
{
  int k;
  int a[100];
} var;

and EXPR a dereference of a pointer (induction variable that goes over
var.a).  In that case, get_ref_base_and_extent will return the offset 0
for EXPR, and we will add SFT of "k" as a virtual operand, instead of the
SFT of "a".

Ideally, we would like to use exactly the same operands as
get_expr_operands returns for EXPR.  This is quite difficult to achieve
at the moment, so this patch makes us take subvars from EXPR if
possible, and all subvars of VAR if not.

Bootstrapped & regtested on i686.

Zdenek

	* tree-ssa-alias.c (new_type_alias): Do not use offset of expr to
	select subvars of var.

Index: tree-ssa-alias.c
===================================================================
*** tree-ssa-alias.c	(revision 118690)
--- tree-ssa-alias.c	(working copy)
*************** new_type_alias (tree ptr, tree var, tree
*** 2756,2761 ****
--- 2756,2764 ----
    tree ali = NULL_TREE;
    HOST_WIDE_INT offset, size, maxsize;
    tree ref;
+   VEC (tree, heap) *overlaps = NULL;
+   subvar_t sv;
+   unsigned int len;
  
    gcc_assert (p_ann->symbol_mem_tag == NULL_TREE);
    gcc_assert (!MTAG_P (var));
*************** new_type_alias (tree ptr, tree var, tree
*** 2768,2780 ****
  
    /* Add VAR to the may-alias set of PTR's new symbol 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;
-       VEC (tree, heap) *overlaps = NULL;
-       unsigned int len;
- 
        for (sv = svars; sv; sv = sv->next)
  	{
            bool exact;
--- 2771,2779 ----
  
    /* Add VAR to the may-alias set of PTR's new symbol tag.  If VAR has
       subvars, add the subvars to the tag instead of the actual var.  */
!   if (var_can_have_subvars (ref)
!       && (svars = get_subvars_for_var (ref)))
      {
        for (sv = svars; sv; sv = sv->next)
  	{
            bool exact;
*************** new_type_alias (tree ptr, tree var, tree
*** 2782,2796 ****
            if (overlap_subvar (offset, maxsize, sv->var, &exact))
              VEC_safe_push (tree, heap, overlaps, sv->var);
          }
!       len = VEC_length (tree, overlaps);
        if (dump_file && (dump_flags & TDF_DETAILS))
!         fprintf (dump_file, "\nnumber of overlapping subvars = %u\n", len);
!       gcc_assert (len);
  
        if (len == 1)
!         ali = add_may_alias_for_new_tag (tag, VEC_index (tree, overlaps, 0));
        else if (len > 1)
!         {
  	  unsigned int k;
  	  tree sv_var;
  
--- 2781,2816 ----
            if (overlap_subvar (offset, maxsize, sv->var, &exact))
              VEC_safe_push (tree, heap, overlaps, sv->var);
          }
!       gcc_assert (overlaps != NULL);
!     }
!   else if (var_can_have_subvars (var)
! 	   && (svars = get_subvars_for_var (var)))
!     {
!       /* If the REF is not a direct access to VAR (e.g., it is a dereference
! 	 of a pointer), we should scan the virtual operands of REF the same
! 	 way as tree-ssa-operands do.  At the moment, this is somewhat
! 	 difficult, so we just give up and add all the subvars of VAR.
! 	 On mem-ssa branch, the scanning for virtual operands have been
! 	 split from the rest of tree-ssa-operands, so it should be much
! 	 easier to fix this problem correctly once mem-ssa is merged.  */
!       for (sv = svars; sv; sv = sv->next)
! 	VEC_safe_push (tree, heap, overlaps, sv->var);
! 
!       gcc_assert (overlaps != NULL);
!     }
!   else
!     ali = add_may_alias_for_new_tag (tag, var);
! 
!   len = VEC_length (tree, overlaps);
!   if (len > 0)
!     {
        if (dump_file && (dump_flags & TDF_DETAILS))
! 	fprintf (dump_file, "\nnumber of overlapping subvars = %u\n", len);
  
        if (len == 1)
! 	ali = add_may_alias_for_new_tag (tag, VEC_index (tree, overlaps, 0));
        else if (len > 1)
! 	{
  	  unsigned int k;
  	  tree sv_var;
  
*************** new_type_alias (tree ptr, tree var, tree
*** 2808,2816 ****
  		}
  	    }
  	}
      }
-   else
-     ali = add_may_alias_for_new_tag (tag, var);
  
    p_ann->symbol_mem_tag = ali;
    TREE_READONLY (tag) = TREE_READONLY (var);
--- 2828,2835 ----
  		}
  	    }
  	}
+       VEC_free (tree, heap, overlaps);
      }
  
    p_ann->symbol_mem_tag = ali;
    TREE_READONLY (tag) = TREE_READONLY (var);


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