public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "absoler at smail dot nju.edu.cn" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/107047] New: load introduced of struct fields after assigning it to a local variable
Date: Tue, 27 Sep 2022 07:25:49 +0000	[thread overview]
Message-ID: <bug-107047-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 107047
           Summary: load introduced of struct fields after assigning it to
                    a local variable
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: absoler at smail dot nju.edu.cn
  Target Milestone: ---

for gcc-12.1.0, with this code:

struct S6 {
   short  f0;
   char  f1;
   int  f2;
};

struct S6 g_36 = {2UL,4L,0x32B3D10AL};
int g_48 = (-1L);


void func_30() {
    struct S6 f[4][7];
    f[1][6] = g_36;
    if (f[1][6].f0 || f[1][6].f1)
        g_48 = f[1][6].f1;
}

when compiled with -O1 option, generated binaries will be like:

0000000000401186 <func_30>:
  401186:       48 83 ec 70             sub    $0x70,%rsp
  40118a:       f7 05 d4 2e 00 00 ff    testl  $0xffffff,0x2ed4(%rip)        #
404068 <g_36>
  401191:       ff ff 00 
  401194:       74 0d                   je     4011a3 <func_30+0x1d>
  401196:       0f be 05 cd 2e 00 00    movsbl 0x2ecd(%rip),%eax        #
40406a <g_36+0x2>
  40119d:       89 05 bd 2e 00 00       mov    %eax,0x2ebd(%rip)        #
404060 <g_48>
  4011a3:       48 83 c4 70             add    $0x70,%rsp
  4011a7:       c3                      retq   

we can see the use of f[1][6] is replaced by g_36 in the if-condition and "g_48
= f[1][6].f1", and the f is not optimized away.

             reply	other threads:[~2022-09-27  7:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-27  7:25 absoler at smail dot nju.edu.cn [this message]
2022-09-27  9:10 ` [Bug middle-end/107047] " rguenth at gcc dot gnu.org
2022-10-05 20:02 ` pinskia at gcc dot gnu.org
2022-10-26  8:31 ` [Bug middle-end/107047] load introduced of struct/union " absoler at smail dot nju.edu.cn

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-107047-4@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).