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 middle-end/55430] [4.8 Regression
Date: Wed, 21 Nov 2012 17:16:00 -0000	[thread overview]
Message-ID: <bug-55430-4-nXMYsMOgxj@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-55430-4@http.gcc.gnu.org/bugzilla/>


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |x86_64-linux
           Priority|P3                          |P1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-11-21
          Component|other                       |middle-end
                 CC|                            |vmakarov at redhat dot com
     Ever Confirmed|0                           |1
   Target Milestone|---                         |4.8.0

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-11-21 17:16:00 UTC ---
This ree.c:61X failure is a LRA caused miscompilation of ree.c apparently.
Reduced self-contained testcase:

struct S
{
  unsigned int s1 : 8;
  unsigned int s2 : 2;
};

int
foo (int x, int y, struct S *z, unsigned int w)
{
  if (z[y].s2 == x && z[y].s1 == w)
    return 1;
  return 0;
}

#ifdef FULL
#include <unistd.h>
#include <sys/mman.h>

int foo (int, int, struct S *, unsigned int) __attribute__((noinline,
noclone));

int
main ()
{
  unsigned long ps = sysconf (_SC_PAGE_SIZE);
  char *p = mmap (NULL, 8 * ps, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  if (p == MAP_FAILED)
    return 0;
  if (mprotect (p + 4 * ps, 4 * ps, PROT_NONE))
    return 0;
  if ((4 * ps / sizeof (struct S)) * sizeof (struct S) != 4 * ps)
    return 0;
  struct S *s = (struct S *) (p + 4 * ps);
  return foo (0, 0, s - 1, 0) != 1;
}
#endif

compile with -O2 on x86_64-linux, and you can see (or when compiled with -O2
-DFULL watch at runtime) that before LRA merge, code like:
        movzbl  1(%rdx), %eax
        andl    $3, %eax
has been generated to read the s2 bitfield, while with LRA it is
        movl    1(%rdx), %esi
        andl    $3, %esi
instead (note movl instead of movzbl).  But the structure (in ree.c s2 is kind
and struct S is struct ext_modified) is 4 bytes long, thus reading 4 bytes from
the start of the structure + 1 byte is potentially going to trap if the
structure is at the end of some page (as -DFULL shows).
In *.ira we have:
(insn 15 12 16 2 (set (reg:QI 80 [ *_6+1 ])
        (mem:QI (plus:DI (reg/f:DI 62 [ D.1744 ])
                (const_int 1 [0x1])) [2 *_6+1 S1 A8])) reetest.c:10 67
{*movqi_internal}
     (expr_list:REG_EQUIV (mem:QI (plus:DI (reg/f:DI 62 [ D.1744 ])
                (const_int 1 [0x1])) [2 *_6+1 S1 A8])
        (nil)))
(note 16 15 17 2 NOTE_INSN_DELETED)
(insn 17 16 7 2 (parallel [
            (set (reg:SI 81 [ D.1742 ])
                (and:SI (subreg:SI (reg:QI 80 [ *_6+1 ]) 0)
                    (const_int 3 [0x3])))
            (clobber (reg:CC 17 flags))
        ]) reetest.c:10 376 {*andsi_1}
     (expr_list:REG_DEAD (reg:QI 80 [ *_6+1 ])
        (expr_list:REG_UNUSED (reg:CC 17 flags)
            (nil))))
which *.reload turns into:
(insn 43 16 17 2 (set (reg:SI 4 si [orig:81 D.1742 ] [81])
        (mem:SI (plus:DI (reg/f:DI 1 dx [orig:62 D.1744 ] [62])
                (const_int 1 [0x1])) [2 *_6+1 S4 A8])) reetest.c:10 65
{*movsi_internal}
     (nil))
(insn 17 43 44 2 (parallel [
            (set (reg:SI 4 si [orig:81 D.1742 ] [81])
                (and:SI (reg:SI 4 si [orig:81 D.1742 ] [81])
                    (const_int 3 [0x3])))
            (clobber (reg:CC 17 flags))
        ]) reetest.c:10 376 {*andsi_1}
     (nil))


  reply	other threads:[~2012-11-21 17:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-21 17:07 [Bug other/55430] New: " jakub at gcc dot gnu.org
2012-11-21 17:16 ` jakub at gcc dot gnu.org [this message]
2012-11-23  1:29 ` [Bug middle-end/55430] [4.8 Regression] LRA miscompilation of ree.c vmakarov at gcc dot gnu.org
2012-11-23 15:14 ` jakub at gcc dot gnu.org
2012-11-27 11:07 ` jakub 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-55430-4-nXMYsMOgxj@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).