On Mon, 8 Aug 2016, Bernd Edlinger wrote:
> Hi!
>
>
> As described in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71083
> we generate unaligned accesses because tree-predcom rewrites
> bitfield and packed accesses in a way that looses the proper
> alignment information.
>
> The attached patch fixes this by re-using the gimple memory
> expression from the original access.
>
> I was not sure, if any non-constant array references would be
> valid at where the ref_at_iteration is expanded, I set these
> to the array-lower-bound, as the DR_OFFSET contains the folded
> value of all non-constant array references.
>
> The patch compensates for the constant offset from the outer
> reference to the inner reference, and replaces the inner
> reference instead of the outer reference.
>
>
> Boot-strapped and reg-tested on x86_64-linux-gnu.
> OK for trunk?
I don't think what you do is correct. Consider
for (i)
for (j)
{
... = a[i][j];
}
predcom considers innermost loops only and thus the DRs will
be analyzed with respect to that which means DR_BASE_ADDRESS
is &a[i][0] but you end up generating (*(&a) + i * ..)[0][0]
which is at best suspicious with respect to further analyses
by data-ref and TBAA. Also note that this may get alignment
wrong as well as changing [i] to [0] may lead to false alignment
(consider a [2][2] char array aligned to 4 bytes).
Your patch goes halfway back to code we had in the past
(looking at the 4.3 branch right now) which had numerous
issues (don't remember exactly).
I believe that if we'd handle bitfields by
if (TREE_CODE (DR_REF (dr)) == COMPONENT_REF
&& DECL_BIT_FIELD_TYPE (TREE_OPERAND (DR_REF (dr), 1)))
ref = TREE_OPERAND (DR_REF (dr), 0);
else
ref = DR_REF (dr);
unsigned align = get_object_alignment (ref);
and use the type / alignment of that ref for the built MEM_REF
(with coff adjusted by the split bitfield component-ref offset)
and build a COMPONENT_REF around the MEM_REF to handle the
bitfield part this should work ok.
Richard.
>
> Thanks
> Bernd.
>
--
Richard Biener <[email protected]>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB
21284 (AG Nuernberg)