public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug ipa/98834] [10/11 Regression] Code path incorrectly determined to be unreachable
Date: Mon, 15 Mar 2021 12:40:39 +0000	[thread overview]
Message-ID: <bug-98834-4-nDgjXj6s6z@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-98834-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
So for the missed optimization we run into

  /* 5) For aggregate copies translate the reference through them if
     the copy kills ref.  */
  else if (data->vn_walk_kind == VN_WALKREWRITE
...
      /* Adjust *ref from the new operands.  */
      ao_ref rhs1_ref;
      ao_ref_init (&rhs1_ref, rhs1);
      if (!ao_ref_init_from_vn_reference (&r, ao_ref_alias_set (&rhs1_ref),
                                          ao_ref_base_alias_set (&rhs1_ref),
                                          vr->type, vr->operands))
        return (void *)-1;
      /* This can happen with bitfields.  */
      if (maybe_ne (ref->size, r.size))
        return (void *)-1;

because the IL looks like

  __xD.2835 = __xD.2753._M_dataD.2625;
  __xx_11 = MEM <intD.9> [(struct _TupleD.2456 *)&__xD.2835];

and we try to express the load in terms of the RHS of the aggregate copy
but we end up with __xD.2753._M_dataD.2625 itself (there's no subsetting
component ref on the original load) but that loads 64 bytes, not 32 as
requested.  The code tries to handle variable index accesses and thus
doesn't simply try to compute base + offset and a corresponding MEM_REF
to look up.

The following seems to work but is otherwise untested:

diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index e3806e55457..c47bd19a1fa 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -3306,7 +3306,17 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void
*data_,
        return (void *)-1;
       /* This can happen with bitfields.  */
       if (maybe_ne (ref->size, r.size))
-       return (void *)-1;
+       {
+         /* If the access lacks some subsetting simply apply that by
+            shortening it.  That in the end can only be successful
+            if we can pun the lookup result which in turn requires
+            exact offsets.  */
+         if (known_eq (r.size, r.max_size)
+             && known_lt (ref->size, r.size))
+           r.size = r.max_size = ref->size;
+         else
+           return (void *)-1;
+       }
       *ref = r;

       /* Do not update last seen VUSE after translating.  */

  parent reply	other threads:[~2021-03-15 12:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-26  8:28 [Bug tree-optimization/98834] New: " kretz at kde dot org
2021-01-26  9:18 ` [Bug ipa/98834] [10/11 Regression] " rguenth at gcc dot gnu.org
2021-01-26  9:20 ` kretz at kde dot org
2021-01-26  9:29 ` kretz at kde dot org
2021-01-26  9:47 ` jakub at gcc dot gnu.org
2021-01-26 10:09 ` rguenther at suse dot de
2021-03-08 18:10 ` jamborm at gcc dot gnu.org
2021-03-15 12:40 ` rguenth at gcc dot gnu.org [this message]
2021-03-15 15:00 ` cvs-commit at gcc dot gnu.org
2021-03-15 15:02 ` rguenth at gcc dot gnu.org
2021-03-16  9:29 ` marxin at gcc dot gnu.org
2021-03-24 13:12 ` [Bug ipa/98834] [10 " rguenth at gcc dot gnu.org
2021-03-24 14:26 ` cvs-commit at gcc dot gnu.org
2021-03-24 14:27 ` rguenth at gcc dot gnu.org

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=bug-98834-4-nDgjXj6s6z@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).