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 tree-optimization/113727] [14 Regression] csmith: differences from nothing to -O1 since r14-4612-g6decda1a35be57
Date: Tue, 19 Mar 2024 13:40:09 +0000	[thread overview]
Message-ID: <bug-113727-4-QE2P50tUXX@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-113727-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #23 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note with the 2nd patch it's still broken when the BIT_FIELD_REFs in the IL are
not byte aligned.

Both patches passed bootstrap & regtest, there is unknown effect on
optimization of __imag / __real.

Looking at such an example we see

  _1 = x.f;
  s$f = _1;
  REALPART_EXPR <s$f> = 1.0e+0;
  _7 = s$f;
  s.f = _7;
  bar (s);

so while we don't "handle" REALPART_EXPR we assume its base is fully
replaced.  For the BIT_FIELD_REF case we cannot know any such thing.

Ah, and the fix is a bit wrong I guess.  It should be

diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc
index f8e71ec48b9..f8176de817f 100644
--- a/gcc/tree-sra.cc
+++ b/gcc/tree-sra.cc
@@ -2358,6 +2358,12 @@ sort_and_splice_var_accesses (tree var)
          j++;
        }

+      /* When there is a partial LHS involved we have no way to see what it
+        accesses, so if it's not the only access to the subregion
+        we have to fail.  */
+      if (grp_partial_lhs && j != i + 1)
+       return NULL;
+
       i = j;

       access->group_representative = access;

and that indeed does disable SRA for

struct S { _Complex float f; } x;

void bar (struct S);

float foo ()
{
  struct S s;
  s.f = x.f;
  __real s.f = 1.f;
  bar (s);
  float x = __real s.f;
  return x;
}

so maybe grp_partial_lhs isn't supposed to handle the BIT_FIELD_REF case
in question but only handles the case where there's a sub-access in its
base?

I suppose it simply wasn't designed to handle mixed accesses.

Maybe the problem is that SRA fails to see that for a ->grp_partial_lhs
access we _have_ to do a replacement.  For the testcase in this PR the
access is 'as' itself and we create a replacement for as.au and as.f3
but then we have overlapping replacements (with the covering 'as').

The following fixes that, but maybe not in the correct place:

diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc
index f8e71ec48b9..dbfae5e7fdd 100644
--- a/gcc/tree-sra.cc
+++ b/gcc/tree-sra.cc
@@ -2735,7 +2735,8 @@ analyze_access_subtree (struct access *root, struct
access *parent,
     {
       hole |= covered_to < child->offset;
       sth_created |= analyze_access_subtree (child, root,
-                                            allow_replacements && !scalar,
+                                            allow_replacements && !scalar
+                                            && !root->grp_partial_lhs,
                                             totally);

       root->grp_unscalarized_data |= child->grp_unscalarized_data;

  parent reply	other threads:[~2024-03-19 13:40 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-02 19:40 [Bug c/113727] New: csmith: differences from nothing to -O1 dcb314 at hotmail dot com
2024-02-02 20:27 ` [Bug c/113727] " sjames at gcc dot gnu.org
2024-02-02 20:40 ` dcb314 at hotmail dot com
2024-02-02 21:03 ` dcb314 at hotmail dot com
2024-02-02 21:15 ` dcb314 at hotmail dot com
2024-02-02 21:40 ` dcb314 at hotmail dot com
2024-02-02 21:47 ` dcb314 at hotmail dot com
2024-02-02 21:49 ` sjames at gcc dot gnu.org
2024-02-03 10:11 ` xry111 at gcc dot gnu.org
2024-02-03 10:15 ` xry111 at gcc dot gnu.org
2024-02-03 11:07 ` dcb314 at hotmail dot com
2024-02-03 11:08 ` dcb314 at hotmail dot com
2024-02-03 18:54 ` xry111 at gcc dot gnu.org
2024-02-04 19:42 ` [Bug c/113727] [14 Regression] " pinskia at gcc dot gnu.org
2024-03-15 15:01 ` [Bug tree-optimization/113727] " law at gcc dot gnu.org
2024-03-18  8:45 ` sjames at gcc dot gnu.org
2024-03-19  5:58 ` sjames at gcc dot gnu.org
2024-03-19  6:04 ` sjames at gcc dot gnu.org
2024-03-19  6:09 ` pinskia at gcc dot gnu.org
2024-03-19  6:24 ` pinskia at gcc dot gnu.org
2024-03-19  6:41 ` pinskia at gcc dot gnu.org
2024-03-19  6:47 ` pinskia at gcc dot gnu.org
2024-03-19  9:46 ` [Bug tree-optimization/113727] [14 Regression] csmith: differences from nothing to -O1 since r14-4612-g6decda1a35be57 rguenth at gcc dot gnu.org
2024-03-19 10:51 ` rguenth at gcc dot gnu.org
2024-03-19 11:22 ` rguenth at gcc dot gnu.org
2024-03-19 13:40 ` rguenth at gcc dot gnu.org [this message]
2024-03-21  7:33 ` cvs-commit at gcc dot gnu.org
2024-03-21  7:34 ` 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-113727-4-QE2P50tUXX@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).