public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/108516] New: Useless movzx instruction emitted when loading 8 bits from 24 bit struct
@ 2023-01-24 11:01 jzwinck at gmail dot com
  2023-01-24 13:15 ` [Bug target/108516] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: jzwinck at gmail dot com @ 2023-01-24 11:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108516
           Summary: Useless movzx instruction emitted when loading 8 bits
                    from 24 bit struct
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jzwinck at gmail dot com
  Target Milestone: ---

This code produces an extra instruction in GCC 11 and 12 (but not 10 or
before):

    #include <stdint.h>

    struct S
    {
        uint8_t e1;
        uint8_t e2;
        uint8_t e3;
    };

    uint32_t f2(S s) { return s.e2; }

The generated code is:

        mov     eax, edi
        movzx   eax, ah
        movzx   eax, al
        ret

The movzx from "al" is useless: it zeros the high 24 bits of eax which are
known to be zero after the prior movzx.  GCC 10 and earlier do not emit the
useless instruction, and neither do GCC 11 or 12 if the struct contains 4 bytes
instead of 3.

Demo: https://godbolt.org/z/Wajo86GfM

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

end of thread, other threads:[~2023-02-13 20:04 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-24 11:01 [Bug rtl-optimization/108516] New: Useless movzx instruction emitted when loading 8 bits from 24 bit struct jzwinck at gmail dot com
2023-01-24 13:15 ` [Bug target/108516] " pinskia at gcc dot gnu.org
2023-01-24 13:15 ` pinskia at gcc dot gnu.org
2023-01-24 13:18 ` [Bug rtl-optimization/108516] " pinskia at gcc dot gnu.org
2023-01-28  7:36 ` crazylht at gmail dot com
2023-02-10 22:07 ` pinskia at gcc dot gnu.org
2023-02-10 22:34 ` levo.delellis at gmail dot com
2023-02-13  8:49 ` ubizjak at gmail dot com
2023-02-13 19:24 ` [Bug target/108516] " cvs-commit at gcc dot gnu.org
2023-02-13 20:04 ` [Bug target/108516] [11/12 Regression] " ubizjak at gmail dot com

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