[PATCH] Start to Fix PR 28436: accessing an element via a "pointer" on a vector does not cause vec_extract to be used

Andrew_Pinski@PlayStation.Sony.Com Andrew_Pinski@PlayStation.Sony.Com
Tue Nov 21 07:46:00 GMT 2006

  This patch starts to fix PR 28436 by folding *(type*)&vector_type_var 
BIT_FIELD_REF<width,0, vector_type_var>.  To be able to do that, we need 
to introduce the concept
that a vector variable is sometimes not a gimple register, other wise we 
end up with a SSA_NAME
inside BIT_FIELD_REF on the left hand side which is invalid as 
BIT_FIELD_REF only modifies part
of the register (in way a subreg).  I converted DECL_COMPLEX_GIMPLE_REG_P 
for this reason.  Next I noticed in some cases SRA would cause us to 
create BIT_FIELD_REF on the left hand
side with a SSA_NAME in it, this patch fixes that also. 

On the expand side, we have some cases where the vec_extract would not use 
the correct mode because of
VIEW_CONVERT_EXPR.  This fixes the problem by getting the correct mode in 
get_inner_reference for
BIT_FIELD_REF/VECTOR_TYPE cases and by trying to get a correct vector mode 
in extract_bit_field if
that failed and then if all else fails, use gen_lowpart in 

I added testcase for all these failures I saw since there were not many 
for vectors yet.

OK? Bootstrapped and tested on i686-linux-gnu with no regressions.

Is this patch too big and should I split up the patch into smaller pieces.
I could split out the DECL_GIMPLE_REG_P part and the fold-const.c part if
anyone wants it done that way.

Andrew Pinski

PS I Noticed that the x86's vec_extract always tries to use SF mode so we 
don't get
this optimization for:

int f(vector int a)
  return *(int*)&a;


        * tree.h (DECL_COMPLEX_GIMPLE_REG_P): Rename to ...
        (DECL_GIMPLE_REG_P): This.
        * fold-const.c (fold_indirect_ref_1): Fold *(foo *)&vectorfoo into
        using BIT_FIELD_REF.
        * omp-low.c (omp_copy_decl_2): Use the renamed DECL_GIMPLE_REG_P.
        * tree-gimple.c (is_gimple_reg): Use the renamed DECL_GIMPLE_REG_P
        and check for VECTOR_TYPE.
        * expr.c (get_inner_reference): Set the mode for BIT_FIELD_REF 
        vector types.
        * tree-flow-inline.h (var_can_have_subvars): Use the renamed
        * gimplify.c (internal_get_tmp_var): Use the renamed 
        and check for VECTOR_TYPE.
        (gimplify_bind_expr): Likewise.
        (gimplify_function_tree): Likewise.
        * expmed.c: Include target.h.
        (extract_bit_field): For vector mode, try find a better mode 
        If that fails use gen_lowpart (for vectors only).
        * tree-dfa.c (make_rename_temp): Use the renamed DECL_GIMPLE_REG_P
        and check for VECTOR_TYPE.
        * tree-ssa-pre.c (create_expressions_by_pieces): Likewise.
        (insert_into_preds_of_block): Likewise.
        (insert_fake_stores): Create gimple register store_tmps for
        vector types.
        * tree-sra.c (sra_elt): New field, is_vector_lhs.
        (sra_walk_expr <case BIT_FIELD_REF>): For vector types that
        are the left hand side, set the element's is_vector_lhs to true.
        (instantiate_element): For vector types which were on the left
        hand size, set DECL_GIMPLE_REG_P to false.
        * tree-nested.c (create_tmp_var_for): Use the renamed 
        * tree-inline.c (declare_return_variable):  Use the renamed 
        and check for VECTOR_TYPE.
        (copy_decl_to_var):  Use the renamed DECL_GIMPLE_REG_P.
        (copy_result_decl_to_var): Likewise.
        * tree-vect-transform.c (vect_get_new_vect_var): For vector types, 
create a
        gimple register variable.
        * Makefile.in (expmed.o): Update dependencies.

        * gcc.c-torture/compile/vector-1.c: New test.
        * gcc.c-torture/compile/vector-2.c: New test.
        * gcc.c-torture/compile/vector-3.c: New test.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: vectorbitfield.diff.txt
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20061121/3d6883e1/attachment.txt>

More information about the Gcc-patches mailing list