public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/111015] New: __int128 bitfields optimized incorrectly to  the 64 bit operations
@ 2023-08-14 13:53 pshevchuk at pshevchuk dot com
  2023-08-14 14:01 ` [Bug rtl-optimization/111015] " rguenth at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: pshevchuk at pshevchuk dot com @ 2023-08-14 13:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111015
           Summary: __int128 bitfields optimized incorrectly to  the 64
                    bit operations
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pshevchuk at pshevchuk dot com
  Target Milestone: ---

godbolt: https://godbolt.org/z/r5d6ToY1z

Basically, a store of one half of a 70-bit bitfield gets completely optimized
away.
i.e. for 

struct Entry {
    unsigned left : 4;
    unsigned right : 4;
    uint128 key : KEY_BITS;
} data;

the code:

data.left = left;
data.right = right;
data.key = key & KEY_BITS_MASK;

produces the following (amd64):
        andl    $15, %ecx
        salq    $4, %rcx
        andl    $15, %edx
        orq     %rdx, %rcx
        movq    %rdi, %rax
        salq    $8, %rax
        orq     %rax, %rcx
        movq    %rcx, data(%rip)
        andw    $-16384, data+8(%rip)

critically, at no point is there any attempt to actually initialize data+8

The problem does not disappear if the bitfields gets moved around; it is,
however, very finicky with respect to the size of the bitfields.

-O1 -fstore-merging appears to be close to the smallest set of compilation
options at which it fails.

If you replace -O1 with the list of -O1 optimization from here:
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html , it will start
working correctly, so probably we have a documentation issue

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

end of thread, other threads:[~2023-08-30 10:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-14 13:53 [Bug rtl-optimization/111015] New: __int128 bitfields optimized incorrectly to the 64 bit operations pshevchuk at pshevchuk dot com
2023-08-14 14:01 ` [Bug rtl-optimization/111015] " rguenth at gcc dot gnu.org
2023-08-14 14:04 ` [Bug tree-optimization/111015] [11/12/13/14 Regression] " rguenth at gcc dot gnu.org
2023-08-15 23:06 ` mikpelinux at gmail dot com
2023-08-16 15:14 ` mikpelinux at gmail dot com
2023-08-29 12:41 ` jakub at gcc dot gnu.org
2023-08-29 14:24 ` jakub at gcc dot gnu.org
2023-08-30  8:47 ` cvs-commit at gcc dot gnu.org
2023-08-30  9:33 ` cvs-commit at gcc dot gnu.org
2023-08-30  9:49 ` cvs-commit at gcc dot gnu.org
2023-08-30  9:57 ` cvs-commit at gcc dot gnu.org
2023-08-30 10:00 ` jakub 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).