public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: Bernd Edlinger <bernd.edlinger@hotmail.de>
Cc: Eric Botcazou <ebotcazou@adacore.com>,
	    "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
	    Jeff Law <law@redhat.com>, Jakub Jelinek <jakub@redhat.com>
Subject: Re: [PATCH] Fix unaligned access when predictive commoning (PR 71083)
Date: Thu, 11 Aug 2016 07:07:00 -0000	[thread overview]
Message-ID: <alpine.LSU.2.11.1608110904280.26629@t29.fhfr.qr> (raw)
In-Reply-To: <AM4PR0701MB2162CB6B6054642CE6413269E41D0@AM4PR0701MB2162.eurprd07.prod.outlook.com>

On Wed, 10 Aug 2016, Bernd Edlinger wrote:

> On 08/10/16 14:29, Richard Biener wrote:
> > On Tue, 9 Aug 2016, Bernd Edlinger wrote:
> >> We know that the difference between the innermost ref
> >> and the outer ref is byte-aligned, but we do not know
> >> that the same is true for offset between the COMPONENT_REF
> >> and the outer ref.
> >>
> >> I mean boff is essentially the difference between
> >> bitpos of get_inner_reference(exp) and
> >> bitpos of get_inner_reference(TREE_OPERAND (exp, 0))
> >>
> >> This would be exposed by my patch, because previously
> >> we always generated BIT_FIELD_REFS, with bit-offset 0,
> >> but the MEM_REF at the byte-offset there is in all likelihood
> >> pretty much unaligned, the MEM_REF at the COMPONENT_REF
> >> is likely more aligned and allows better code for ARM processors,
> >> but only if the MEM_REF is at a byte-aligned offset at all,
> >> otherwise the whole transformation would be wrong.
> >
> > Note that the important thing to ensure is that the access the
> > MEM_REF performs is correct TBAA-wise which means you either
> > have to use alias-set zero (ptr_type_node offset) or _not_
> > shuffle the offset arbitrarily between the MEM_REF and the
> > components you wrap it in.
> >
> > Richard.
> >
> 
> Yes, the patch exactly replicates the outermost COMPONENT_REF and
> subtracts the component's byte-offset from the MEM_REF's address,
> and the MEM_REF uses the pointer type of the inner reference.
> 
> In the case without bitfields and the Ada bitfields the patch changes
> nothing, except we build an aligned type out of TREE_TYPE (DR_REF (dr))
> and get_object_alignment (DR_REF (dr)).
> 
> In the case with a component_ref that is byte-aligned
> we subtract the component byte offset from the address
> before the MEM_REF is constructed.  And the
> alias_ptr is of type reference_alias_ptr_type
> (TREE_OPERAND (DR_REF (dr), 0)) and again the alignment
> from get_object_alignment (TREE_OPERAND (DR_REF (dr), 0)
> so that should be exactly type-correct from TBAA's perspective.
> 
> 
> Attached a new version of the patch with an improved comment,
> and the new Ada test cases.
> 
> 
> Bootstrap and reg-test on x86_64-pc-linux-gnu without regression.
> Is it OK for trunk?

The patch looks mostly ok, but

+      else
+       {
+         boff >>= LOG2_BITS_PER_UNIT;
+         boff += tree_to_uhwi (component_ref_field_offset (ref));
+         coff = size_binop (MINUS_EXPR, coff, ssize_int (boff));

how can we be sure that component_ref_field_offset is an INTEGER_CST?
At least Ada can have variably-length fields before a bitfield.  We'd
need to apply component_ref_field_offset to off in that case.  Which
makes me wonder if we can simply avoid the COMPONENT_REF path in
a first iteration of the patch and always build a BIT_FIELD_REF?
It should solve the correctness issues as well and be more applicable
for branches.

Thanks,
Richard.

  reply	other threads:[~2016-08-11  7:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-08 19:57 Bernd Edlinger
2016-08-09  7:29 ` Richard Biener
2016-08-09 17:31   ` Bernd Edlinger
2016-08-09 20:48     ` Eric Botcazou
2016-08-09 22:23       ` Bernd Edlinger
2016-08-10  8:47         ` AW: " Bernd Edlinger
2016-08-10 12:19           ` Eric Botcazou
2016-08-10 12:29         ` Richard Biener
2016-08-10 16:24           ` Bernd Edlinger
2016-08-11  7:07             ` Richard Biener [this message]
2016-08-11 10:09               ` Bernd Edlinger
2016-08-11 10:30                 ` Richard Biener
2016-08-11 19:47               ` [PATCH] Increase alignment for bit-field " Bernd Edlinger
2016-08-12  7:13                 ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LSU.2.11.1608110904280.26629@t29.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=bernd.edlinger@hotmail.de \
    --cc=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=law@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).