public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "lh_mouse at 126 dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/81456] [11/12/13/14 Regression] x86-64 optimizer makes wrong decision when optimizing for size
Date: Thu, 28 Dec 2023 02:58:51 +0000	[thread overview]
Message-ID: <bug-81456-4-W3PXHjvaYN@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-81456-4@http.gcc.gnu.org/bugzilla/>

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

LIU Hao <lh_mouse at 126 dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lh_mouse at 126 dot com

--- Comment #12 from LIU Hao <lh_mouse at 126 dot com> ---
Is this the same issue?

https://gcc.godbolt.org/z/sTs3E9EP1
```
struct stack
  {
    void** base;
    unsigned int top, cap;
  };

struct context
  {
    void* data;
    stack* st;
  };

int
clear_stack(context& ctx)
  {
    ctx.st->top = 0;
    return 0;
  }
```

GCC reuses RAX for `ctx.st` and the return value, so an extra XOR is generated:
```
clear_stack(context&):
 mov    rax,QWORD PTR [rdi+0x8]
 xor    edx,edx                  <-- this would be unnecessary if
                                     `xor eax, eax` was lifted here
 mov    DWORD PTR [rax+0x8],edx
 xor    eax,eax
 ret
```

as in
```
clear_stack_2(context&):
 mov    rcx,QWORD PTR [rdi+0x8]    # 48 8b 4f 08
 xor    eax,eax                    # 31 c0
 mov    DWORD PTR [rcx+0x8],eax    # 89 41 08
 ret                               # c3
```

      parent reply	other threads:[~2023-12-28  2:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-81456-4@http.gcc.gnu.org/bugzilla/>
2021-05-14  9:49 ` [Bug target/81456] [9/10/11/12 " jakub at gcc dot gnu.org
2021-06-01  8:09 ` rguenth at gcc dot gnu.org
2022-05-27  9:37 ` [Bug target/81456] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:33 ` jakub at gcc dot gnu.org
2023-07-07 10:32 ` [Bug target/81456] [11/12/13/14 " rguenth at gcc dot gnu.org
2023-12-28  2:58 ` lh_mouse at 126 dot com [this message]

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