https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68786

--- Comment #4 from rguenther at suse dot de <rguenther at suse dot de> ---
On Tue, 8 Dec 2015, jakub at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68786
> 
> --- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
> For normal vectorized stores, the alignment is preserved through the
> MEM_REF/TARGET_MEM_REF type, e.g.
> 5991                      TREE_TYPE (data_ref)
> 5992                        = build_aligned_type (TREE_TYPE (data_ref),
> 5993                                              align * BITS_PER_UNIT);
> but for masked loads/stores we don't have that available, all we record is
> the pointer (what we put as TREE_OPERAND (mem_ref, 0)), which can have
> arbitrary type, and the aliasing pointer (with always zero constant).
> The alignment info we record through:
>           set_ptr_info_alignment (get_ptr_info (dataref_ptr), align,
>                                   misalign);
> Unfortunately, it seems that this way we rely on the optimizers not to lose 
> the
> alignment in the points to info, otherwise get_object_alignment_2 assumes the
> pointer is fully aligned.
> In *.vect it is still preserved:
>   # PT = nonlocal escaped
>   # ALIGN = 8, MISALIGN = 0
>   vectp_pretmp.14_77 = vectp_pretmp.14_74 + 32;
>   # USE = anything
>   # CLB = anything
>   MASK_STORE (vectp_pretmp.14_77, 0B, mask__ifc__37.13_72, vect_cst__73);
> but then comes ivopts and turns that into:
>   _36 = ivtmp.32_7 + 32;
>   # PT = nonlocal escaped
>   _37 = (vector(4) double *) _36;
>   # PT = nonlocal escaped
>   # ALIGN = 8, MISALIGN = 0
>   vectp_pretmp.14_77 = _37;
>   # USE = anything
>   # CLB = anything
>   MASK_STORE (vectp_pretmp.14_77, 0B, mask__ifc__37.13_72, vect_cst__73);
> and then dom3 turns this into:
>   _36 = ivtmp.32_7 + 32;
>   # PT = nonlocal escaped
>   _37 = (vector(4) double *) _36;
>   # PT = nonlocal escaped
>   # ALIGN = 8, MISALIGN = 0
>   vectp_pretmp.14_77 = _37;
>   # USE = anything
>   # CLB = anything
>   MASK_STORE (_37, 0B, mask__36.12_70, { 1.0e+0, 1.0e+0, 1.0e+0, 1.0e+0 });
> and the points to info is there already only on a SSA_NAME that has zero uses.
> 
> So, I think that we need to store the original alignment from the 
> vectorization
> time somewhere else, so it is not an optimization to have that info preserved.
> As the second argument of MASK_{LOAD,STORE} ifn is always 0, and all it 
> matters
> is the type on it, perhaps we could stick the alignment in that argument in
> there?  I.e. call get_object_alignment for the original load/store during
> tree-if-conversion.c, in the vectorizer store:
>   misalign ? misalign & -misalign : align
> as INTEGER_CST with the type we were using on the 0 pointer now, and then
> during expansion use build_int_cst (TREE_TYPE (gimple_call_arg (stmt, 1)), 0)
> instead of gimple_call_arg (stmt, 1), and the actual value use to
> build_aligned_type from the rhs type.  Richard, are you ok with that
> representation?
> 
> And then of course is the optimization question, that it is bad that the 
> points
> to / alignment info is lost due to what ivopts and following optimization
> passes perform.  Should we have some late ccp pass that recomputes it, or 
> teach
> ivopts to to add alignment/points to info to the stuff it creates, or teach
> some optimizations that if they replace one pointer with another defined in 
> the
> same bb and the old one has more precise points to info (or similarly for
> integers and value ranges) that it could stick that better info onto the other
> SSA_NAME?

I think you need the alignment on the actual reference if it is needed
for correctness (or always assume unaligned instead of using an aligned
type).  Yes, the alias type pointer can be used as vehicle for misalign
info.

Sure it's "bad" when we lose the info but this just can happen...
(eventually we can track down offenders and try to preserve it)

Reply via email to