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 tree-optimization/114489] New: introduced redundant load facing different branches
Date: Tue, 26 Mar 2024 20:09:52 +0000	[thread overview]
Message-ID: <bug-114489-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 114489
           Summary: introduced redundant load facing different branches
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: absoler at smail dot nju.edu.cn
  Target Milestone: ---

similar with https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107050, but without
function call.

```
int f = 1;
int g1, g2, arr[10];

int func_1() {
    int a = 4;
    int *p1 = &g1;
    if (f) {
        arr[0] = g2;
        int *p2 = &a;
        a = 1;
    }
    *p1 &= (a > 9) - 5;
    return a;
}

int main() {
    func_1();
}
```
gcc-13.2.0 -O1 generates:
```
func_1():
  401106:       mov    0x2f80(%rip),%eax        # 40408c <g1>  # first load
  40110c:       mov    $0x4,%edx
  401111:       cmpl   $0x0,0x2f10(%rip)        # 404028 <f>
  401118:       je     401131 <func_1+0x2b>
  40111a:       mov    0x2f68(%rip),%eax        # 404088 <g2>
  401120:       mov    %eax,0x2f3a(%rip)        # 404060 <arr>
  401126:       mov    0x2f60(%rip),%eax        # 40408c <g1>  # second load
  40112c:       mov    $0x1,%edx
  401131:       and    $0xfffffffb,%eax
  401134:       mov    %eax,0x2f52(%rip)        # 40408c <g1>
  40113a:       mov    %edx,%eax
  40113c:       retq   
```

I wonder why compiler won't use another register to hold `g2`, so that the
second load is unnecessary.

             reply	other threads:[~2024-03-26 20:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-26 20:09 absoler at smail dot nju.edu.cn [this message]
2024-03-26 20:18 ` [Bug tree-optimization/114489] " pinskia at gcc dot gnu.org
2024-03-26 20:19 ` pinskia 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-114489-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).