public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/57344] [4.7/4.8/4.9 Regression] wrong code with pragma pack(1) and -O1 on x86
Date: Tue, 21 May 2013 09:15:00 -0000	[thread overview]
Message-ID: <bug-57344-4-GAGQPJHsda@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-57344-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Yeah, the problem is definitely in store_split_bit_field.

One possible fix is:

--- gcc/expmed.c.jj    2013-05-14 10:54:58.000000000 +0200
+++ gcc/expmed.c    2013-05-21 10:54:59.707793889 +0200
@@ -1094,10 +1094,15 @@ store_split_bit_field (rtx op0, unsigned
       thispos = (bitpos + bitsdone) % unit;

       /* When region of bytes we can touch is restricted, decrease
-     UNIT close to the end of the region as needed.  */
+     UNIT close to the end of the region as needed.
+     Don't do this if op0 is a REG or SUBREG, there won't be any
+     data races on registers and the code assumes unit is
+     BITS_PER_WORD.  */
       if (bitregion_end
       && unit > BITS_PER_UNIT
-      && bitpos + bitsdone - thispos + unit > bitregion_end + 1)
+      && bitpos + bitsdone - thispos + unit > bitregion_end + 1
+      && !REG_P (op0)
+      && GET_CODE (op0) != SUBREG)
     {
       unit = unit / 2;
       continue;

Another one I'm currently testing is just not assuming unit is BITS_PER_WORD in
the SUBREG/REG handling code, and another one a mixture of both.

I don't know if we can actually end up with a SUBREG of MEM, if yes, then the
above patch is wrong, because it could introduce a data race in that case.  The
other fix on the other side might pessimize the case where we e.g. have a real
REG or SUBREG of some REG and store some bits in a first word and bitregion_end
tells us that we must not touch the last byte in the second word, but we need
to touch the rest.  On REGs there should be no data races.  So I'm probably
going with both changes together.


  parent reply	other threads:[~2013-05-21  9:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-20 21:38 [Bug target/57344] New: " dhazeghi at yahoo dot com
2013-05-21  8:19 ` [Bug middle-end/57344] [4.8/4.9 Regression] " jakub at gcc dot gnu.org
2013-05-21  9:08 ` [Bug rtl-optimization/57344] [4.7/4.8/4.9 " rguenth at gcc dot gnu.org
2013-05-21  9:15 ` jakub at gcc dot gnu.org [this message]
2013-05-21 10:18 ` jakub at gcc dot gnu.org
2013-05-23  9:21 ` [Bug rtl-optimization/57344] [4.7 " jakub at gcc dot gnu.org
2014-06-12 13:27 ` 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-57344-4-GAGQPJHsda@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).