public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110459] New: Trivial on stack variable was not optimized away
@ 2023-06-28 15:12 antoshkka at gmail dot com
  2023-06-28 18:03 ` [Bug middle-end/110459] " pinskia at gcc dot gnu.org
  2023-06-29  7:07 ` rguenth at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: antoshkka at gmail dot com @ 2023-06-28 15:12 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110459
           Summary: Trivial on stack variable was not optimized away
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: antoshkka at gmail dot com
  Target Milestone: ---

Consider the example:

struct array {
    char data[4];
};

auto sample2(char c) {
  array buffer = {c, 0, 0, 0};
  return buffer;
}


With GCC-14 and -O2 it produces the following assembly:

sample2(char):
        xor     eax, eax
        mov     BYTE PTR [rsp-22], 0
        mov     WORD PTR [rsp-24], ax
        mov     eax, DWORD PTR [rsp-24]
        sal     eax, 8
        mov     al, dil
        ret


It could be further optimized to just:

sample2(char):
        movzx   eax, dil
        ret


Godbolt playground: https://godbolt.org/z/nxKhvo3ns

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/110459] Trivial on stack variable was not optimized away
  2023-06-28 15:12 [Bug tree-optimization/110459] New: Trivial on stack variable was not optimized away antoshkka at gmail dot com
@ 2023-06-28 18:03 ` pinskia at gcc dot gnu.org
  2023-06-29  7:07 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-28 18:03 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
   Last reconfirmed|                            |2023-06-28
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, there might be a dup of this linked to PR 101926 .

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/110459] Trivial on stack variable was not optimized away
  2023-06-28 15:12 [Bug tree-optimization/110459] New: Trivial on stack variable was not optimized away antoshkka at gmail dot com
  2023-06-28 18:03 ` [Bug middle-end/110459] " pinskia at gcc dot gnu.org
@ 2023-06-29  7:07 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-06-29  7:07 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |x86_64-*-*

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Also on x86_64 I see DECL_ALIGN getting in the way of NRV as we seem to up
alignment on locals aggressively but DECL_RETURN stays at what the ABI
mandates.  Of course in this case !aggregate_value_p (result,
current_function_decl) anyway, still this extra copy could be elided IMHO.

Usually this is the job of SRA.

We also perform some of this coalescing in the frontend/gimplifier IIRC,
not sure what prevents it here.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-29  7:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-28 15:12 [Bug tree-optimization/110459] New: Trivial on stack variable was not optimized away antoshkka at gmail dot com
2023-06-28 18:03 ` [Bug middle-end/110459] " pinskia at gcc dot gnu.org
2023-06-29  7:07 ` rguenth at gcc dot gnu.org

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).