public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "torvalds@linux-foundation.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/48696] Horrible bitfield code generation on x86
Date: Wed, 20 Apr 2011 16:17:00 -0000	[thread overview]
Message-ID: <bug-48696-4-B0xzcNg4fQ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-48696-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48696

--- Comment #11 from Linus Torvalds <torvalds@linux-foundation.org> 2011-04-20 16:16:52 UTC ---
(In reply to comment #8)
> 
> Unfortunately the underlying type isn't easily available (at least I didn't
> yet find it ...).  But I suppose we have to guess anyway considering
> targets that don't handle unaligned accesses well or packed bitfields.
> Thus, an idea was to use aligned word-size loads/stores and only at the
> start/end of a structure fall back to smaller accesses (for strict align
> targets).  

That sounds fine.

The only reason to bother with the "underlying type" is that I suspect it could
be possible for educated programmers to use it as a code generation hint. IOW,
if all the individual fields end up fitting nicely in "char", using that as a
base type (even if the _total_ fields don't fit in a single byte) might be a
good hint for the compiler that it can/should use byte accesses and small
constants.

But using the biggest aligned word-size is probably equally good in practice.

And if you end up narrowing the types on _reads_, I think that's fine on x86. I
forget the exact store buffer forwarding rules (and they probably vary a bit
between different microarchitectures anyway), but I think almost all of them
support forwarding a larger store into a smaller (aligned) load.

It's just the writes that should normally not be narrowed.

(Of course, sometimes you may really want to narrow it. Replacing a

   andl $0xffffff00,(%rax)

with a simple

   movb $0,(%rax)

is certainly a very tempting optimization, but it really only works if there
are no subsequent word-sized loads that would get fouled by the write buffer
entry.


  parent reply	other threads:[~2011-04-20 16:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-20  4:25 [Bug other/48696] New: " torvalds@linux-foundation.org
2011-04-20  4:28 ` [Bug other/48696] " torvalds@linux-foundation.org
2011-04-20  9:44 ` [Bug rtl-optimization/48696] " rguenth at gcc dot gnu.org
2011-04-20 11:48 ` ebotcazou at gcc dot gnu.org
2011-04-20 12:12 ` rguenth at gcc dot gnu.org
2011-04-20 12:15 ` rguenth at gcc dot gnu.org
2011-04-20 15:54   ` Jan Hubicka
2011-04-20 12:59 ` ebotcazou at gcc dot gnu.org
2011-04-20 15:31 ` torvalds@linux-foundation.org
2011-04-20 15:41 ` rguenth at gcc dot gnu.org
2011-04-20 15:41 ` rguenth at gcc dot gnu.org
2011-04-20 15:54 ` hubicka at ucw dot cz
2011-04-20 16:17 ` torvalds@linux-foundation.org [this message]
2011-04-20 16:20 ` jakub at gcc dot gnu.org
2011-04-21 15:44 ` joseph at codesourcery dot com
2011-04-21 15:49 ` rguenther at suse dot de
2011-05-03 11:26 ` rguenth at gcc dot gnu.org
2021-02-11 11:22 ` rguenth 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-48696-4-B0xzcNg4fQ@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).