public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "krebbel at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/108199] Bitfields and storage_order_attribute
Date: Thu, 22 Dec 2022 16:24:11 +0000	[thread overview]
Message-ID: <bug-108199-4-KrCIqG1LEr@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-108199-4@http.gcc.gnu.org/bugzilla/>

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

Andreas Krebbel <krebbel at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |x86_64
              Build|                            |x86_64
           Keywords|                            |wrong-code
               Host|                            |x86_64

--- Comment #2 from Andreas Krebbel <krebbel at gcc dot gnu.org> ---
The testcase does an assigned between two struct with endianess differing from
host endianess (assumed to be little). Here the required byteswaps are supposed
to cancel each other out. After that a bitfield comparison on the target struct
is done. This comparison uses the wrong byte offset into the bitfield:

        testb   $64, 7(%rdi)
        jne     .L11

On a big endian target the first bits in the bitfield are supposed to reside in
the first bytes in memory.

The problem appears to get introduced when dead store elimination removes the
assignment to the target struct in FRE.

Before FRE we  have the following:

  _1 = src_6(D)->a;               bswap
  dst$val_9 = _1;                 bswap
  _2 = BIT_FIELD_REF <dst$val_9, 8, 0>;  bswap
  _3 = _2 & 64;
  if (_3 != 0)
...
This would result in 3 bswaps chained to each other. However, after FRE we have
only two because the dead store to dst$val is removed.

  _1 = src_6(D)->a;
  _2 = BIT_FIELD_REF <_1, 8, 0>;
  _3 = _2 & 64;
  if (_3 != 0)

Now we have only which cancel each other out.

Looks like we have to prevent depending stores/loads with different endianess
from getting removed - perhaps by making them also volatile? I think we have to
keep the number of memory accesses with foreign endianess constant over the
optimizations.

  parent reply	other threads:[~2022-12-22 16:24 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-22 16:08 [Bug tree-optimization/108199] New: " krebbel at gcc dot gnu.org
2022-12-22 16:09 ` [Bug tree-optimization/108199] " krebbel at gcc dot gnu.org
2022-12-22 16:24 ` krebbel at gcc dot gnu.org [this message]
2022-12-22 16:29 ` krebbel at gcc dot gnu.org
2022-12-22 16:39 ` [Bug tree-optimization/108199] Bitfields, unions and SRA " pinskia at gcc dot gnu.org
2022-12-22 17:08 ` krebbel at gcc dot gnu.org
2022-12-22 18:29 ` pinskia at gcc dot gnu.org
2022-12-23  7:53 ` krebbel at gcc dot gnu.org
2023-01-09 13:21 ` rguenth at gcc dot gnu.org
2023-01-09 20:15 ` ebotcazou at gcc dot gnu.org
2023-01-09 20:26 ` pinskia at gcc dot gnu.org
2023-01-09 21:46 ` ebotcazou at gcc dot gnu.org
2023-01-10 11:11 ` ebotcazou at gcc dot gnu.org
2023-01-10 11:24 ` ebotcazou at gcc dot gnu.org
2023-01-11 15:03 ` cvs-commit at gcc dot gnu.org
2023-01-11 15:35 ` krebbel at gcc dot gnu.org
2023-01-11 15:41 ` krebbel at gcc dot gnu.org
2023-01-11 16:11 ` ebotcazou at gcc dot gnu.org
2023-01-11 19:46 ` cvs-commit at gcc dot gnu.org
2023-01-11 19:47 ` cvs-commit at gcc dot gnu.org
2023-01-11 19:48 ` ebotcazou at gcc dot gnu.org

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-108199-4-KrCIqG1LEr@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).