public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114289] New: Non-optimal assembly for accessing bit-fields in packed structs
@ 2024-03-08 22:06 dan at stahlke dot org
  2024-03-08 22:10 ` [Bug tree-optimization/114289] " dan at stahlke dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: dan at stahlke dot org @ 2024-03-08 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114289
           Summary: Non-optimal assembly for accessing bit-fields in
                    packed structs
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dan at stahlke dot org
  Target Milestone: ---

// gcc -O3 -g -Wall -march=haswell -mavx2
// https://godbolt.org/z/Yfb9dnYx4

struct foo {
    int x:31;
} __attribute__((packed));

int fx(struct foo const *o) { return o->x; }

Disassembly:

        movzx   eax, BYTE PTR [rdi+1]
        movzx   edx, BYTE PTR [rdi]
        sal     rax, 8
        or      rax, rdx
        movzx   edx, BYTE PTR [rdi+2]
        sal     rdx, 16
        or      rdx, rax
        movzx   eax, BYTE PTR [rdi+3]
        and     eax, 127
        sal     rax, 24
        or      rax, rdx
        sal     rax, 33
        sar     rax, 33
        ret

Compare to clang:

        mov     eax, dword ptr [rdi]
        add     eax, eax
        sar     eax
        ret

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

end of thread, other threads:[~2024-03-08 22:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-08 22:06 [Bug tree-optimization/114289] New: Non-optimal assembly for accessing bit-fields in packed structs dan at stahlke dot org
2024-03-08 22:10 ` [Bug tree-optimization/114289] " dan at stahlke dot org
2024-03-08 22:10 ` [Bug middle-end/114289] " pinskia at gcc dot gnu.org
2024-03-08 22:11 ` dan at stahlke dot org
2024-03-08 22:12 ` pinskia at gcc dot gnu.org
2024-03-08 22:13 ` pinskia 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).