[PATCH] Fix unaligned access generated by IVOPTS

Eric Botcazou ebotcazou@adacore.com
Fri Jan 10 23:43:00 GMT 2014

[Sorry for dropping the ball here]

> I think that may_be_unaligned_p is just seriously out-dated ... shouldn't it
> be sth like
>   get_object_alignment_1 (ref, &align, &bitpos);
>   if step * BITS_PER_UNIT + bitpos is misaligned
> ...
> or rather all this may_be_unaligned_p stuff should be dropped and IVOPTs
> should finally generate proper [TARGET_]MEM_REFs instead?  That is,
> we already handle aliasing fine:
>   ref = create_mem_ref (&bsi, TREE_TYPE (*use->op_p), &aff,
>                         reference_alias_ptr_type (*use->op_p),
>                         iv, base_hint, data->speed);
> so just also handle alignment properly by passing down
> get_object_alignment (*use->op_p) and in create_mem_ref_raw
> do at the end do the
>   if (TYPE_MODE (type) != BLKmode
>       && GET_MODE_ALIGNMENT (TYPE_MODE (type)) > align)
>     type = build_aligned_type (type, align);
> for BLKmode we already look at TYPE_ALIGN and as we do not change
> the access type(?) either the previous code was already wrong or it was
> fine, so there is nothing to do.
> So - if you want to give it a try...?

After a bit of pondering, I'm not really thrilled, as this would mean changing 
TARGET_MEM_REF to accept invalid (unaligned) memory references for the target.  
But I agree that may_be_unaligned_p is seriously outdated, so the attached 
patch entirely rewrites it, fixing the bug in the process.

Tested on SPARC, SPARC64, IA-64 and ARM, OK for the mainline?

2014-01-10  Eric Botcazou  <ebotcazou@adacore.com>

	* builtins.c (get_object_alignment_2): Minor tweak.
	* tree-ssa-loop-ivopts.c (may_be_unaligned_p): Rewrite.

Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.diff
Type: text/x-patch
Size: 2639 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20140110/8669ccda/attachment.bin>

More information about the Gcc-patches mailing list