public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Jeff Law <law@redhat.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [RFA] [tree-optimization/80576] Handle non-constant sizes in DSE
Date: Mon, 16 Sep 2019 09:12:00 -0000	[thread overview]
Message-ID: <CAFiYyc3N3-i2iXqk17SAU6oN-PbVtc1F0uvyqHDGV0vSz2gafQ@mail.gmail.com> (raw)
In-Reply-To: <fea98f20-cd70-400a-6cd9-9b5c4195f196@redhat.com>

On Mon, Sep 9, 2019 at 10:10 PM Jeff Law <law@redhat.com> wrote:
>
> On 8/26/19 3:00 AM, Richard Biener wrote:
> > On Fri, Aug 23, 2019 at 9:19 PM Jeff Law <law@redhat.com> wrote:
> >>
> >> On 8/22/19 4:46 AM, Richard Biener wrote:
> >>>>> Also you seem to use this info to constrain optimization when you
> >>>>> might remember that types of addresses do not carry such information...
> >>>>> Thus it should be "trivially" possible to write a testcase that is miscompiled
> >>>>> after your patch.  I also don't see this really exercised in the
> >>>>> testcases you add?
> >>>> Arggh.  You're absolutely correct.  I must be blocking out that entire
> >>>> discussion from last summer due to the trama :-)
> >>>>
> >>>> If the destination is the address of a _DECL node, can we use the size
> >>>> of the _DECL?
> >>>
> >>> Yes, but this should already happen for both invariant ones like &a.b.c
> >>> and variant ones like &a.b[i].c in ao_ref_init_from_ptr_and_size.
> >> I don't see that in ao_ref_init_from_ptr_and_size.  AFAICT if you don't
> >> know the size when you call that routine (size == NULL), then you end up
> >> with the ref->size and ref->max_size set to -1.
> >>
> >> Am I missing something here?
> >
> > Ah, of course.  ao_ref_from_ptr_and_size would need to be extended
> > to constrain max_size.  So what I was
> > saying is that ao_ref_init_from_ptr_and_size should get you
> > a DECL ao_ref_base () from which you could constrain max_size with.
> > Or rather ao_ref_from_ptr_and_size should be extended do that,
> > mimicing what get_ref_base_and_extent does at the end in the
> > if (DECL_P (exp)) case (mind flag_unconstrained_commons!).
> So I was going to use get_ref_base_and_extent from within
> ao_ref_init_from_ptr_and_size to capture these cases, but
> get_ref_base_and_extent internally uses TYPE_SIZE to get the maximum
> size of the referenced object.
>
> That likely represents a codegen bug waiting to happen.

Yeah, you can't use get_ref_base_and_extent literally here.

> I'll see if I can refactor just the bits we want so that we're not
> duplicating anything.

Not sure if that's too important.  But yes, splitting out

  if (DECL_P (exp))
    {
      if (VAR_P (exp)
          && ((flag_unconstrained_commons && DECL_COMMON (exp))
              || (DECL_EXTERNAL (exp) && seen_variable_array_ref)))
        {
          tree sz_tree = TYPE_SIZE (TREE_TYPE (exp));
          /* If size is unknown, or we have read to the end, assume there
             may be more to the structure than we are told.  */
          if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
              || (seen_variable_array_ref
                  && (sz_tree == NULL_TREE
                      || !poly_int_tree_p (sz_tree)
                      || maybe_eq (bit_offset + maxsize,
                                   wi::to_poly_offset (sz_tree)))))
            maxsize = -1;
        }
      /* If maxsize is unknown adjust it according to the size of the
         base decl.  */
      else if (!known_size_p (maxsize)
               && DECL_SIZE (exp)
               && poly_int_tree_p (DECL_SIZE (exp)))
        maxsize = wi::to_poly_offset (DECL_SIZE (exp)) - bit_offset;
    }
  else if (CONSTANT_CLASS_P (exp))
    {
      /* If maxsize is unknown adjust it according to the size of the
         base type constant.  */
      if (!known_size_p (maxsize)
          && TYPE_SIZE (TREE_TYPE (exp))
          && poly_int_tree_p (TYPE_SIZE (TREE_TYPE (exp))))
        maxsize = (wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (exp)))
                   - bit_offset);
    }

into a helper with just the computed offset as argument
(plus maybe that seen_variable_array_ref which is meaningless
for the address case or rather has to be assumed true(?)) should be possible.

Richard.

>
> Jeff

  reply	other threads:[~2019-09-16  9:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-16 18:10 Jeff Law
2019-08-16 19:55 ` Marc Glisse
2019-08-16 20:41   ` Jeff Law
2019-08-16 22:49     ` Martin Sebor
2019-08-22  0:30       ` Jeff Law
2019-08-22 18:50         ` Martin Sebor
2019-08-23 16:50           ` Jeff Law
2019-08-19 14:23     ` Richard Biener
2019-08-22  2:12       ` Jeff Law
2019-08-22 11:14         ` Richard Biener
2019-08-23 20:27           ` Jeff Law
2019-08-26 10:07             ` Richard Biener
2019-09-03 21:24               ` Jeff Law
2019-09-09 20:10               ` Jeff Law
2019-09-16  9:12                 ` Richard Biener [this message]
2019-09-16  9:18                   ` Richard Biener
2019-08-22 15:53         ` Martin Sebor
2019-08-23 16:50           ` Jeff Law
2019-08-16 21:50   ` Jeff Law
2019-08-16 22:19     ` Marc Glisse
2019-08-16 22:43       ` Jeff Law

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=CAFiYyc3N3-i2iXqk17SAU6oN-PbVtc1F0uvyqHDGV0vSz2gafQ@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --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).