public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/53362] New: gcc 4.7 generates invalid code with -O3 and -mtune=bdver2
@ 2012-05-15 15:38 valerio at aimale dot com
  2012-05-15 17:49 ` [Bug target/53362] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: valerio at aimale dot com @ 2012-05-15 15:38 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53362
           Summary: gcc 4.7 generates invalid code with -O3 and
                    -mtune=bdver2
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: valerio@aimale.com


Hello,

I'm compiling R 2.15.0 on an AMD FX-8150, trying to take advantage of the
bdver2 platform.

The function jumpfun() in src/main/context.c is

/* jumpfun - jump to the named context */
===============================
static void jumpfun(RCNTXT * cptr, int mask, SEXP val)
{
    Rboolean savevis = R_Visible;

    /* run onexit/cend code for all contexts down to but not including
       the jump target */
    PROTECT(val);
    R_run_onexits(cptr);
    UNPROTECT(1);
    R_Visible = savevis;

    R_ReturnedValue = val;
    R_GlobalContext = cptr; /* this used to be set to
                               cptr->nextcontext for non-toplevel
                               jumps (with the context set back at the
                               SETJMP for restarts).  Changing this to
                               always using cptr as the new global
                               context should simplify some code and
                               perhaps allow loops to be handled with
                               fewer SETJMP's.  LT */
    R_restore_globals(R_GlobalContext);

    LONGJMP(cptr->cjmpbuf, mask);
}
================================
with LONGJMP being

# define LONGJMP(x,i) siglongjmp(x,i)

With -O3 -mtune=bdver2 jumpfun() is compiled to:

0000000000000360 <jumpfun>:
     360:       41 56                   push   %r14
     362:       41 55                   push   %r13
     364:       41 89 f5                mov    %esi,%r13d
     367:       41 54                   push   %r12
     369:       49 89 d4                mov    %rdx,%r12
     36c:       55                      push   %rbp
     36d:       48 8b 2d 00 00 00 00    mov    0x0(%rip),%rbp        # 374
<jumpfun+0x14>
     374:       53                      push   %rbx
     375:       48 89 fb                mov    %rdi,%rbx
     378:       48 89 d7                mov    %rdx,%rdi
     37b:       44 8b 75 00             mov    0x0(%rbp),%r14d
     37f:       e8 00 00 00 00          callq  384 <jumpfun+0x24>
     384:       48 89 df                mov    %rbx,%rdi
     387:       e8 00 00 00 00          callq  38c <jumpfun+0x2c>
     38c:       bf 01 00 00 00          mov    $0x1,%edi
     391:       e8 00 00 00 00          callq  396 <jumpfun+0x36>
     396:       48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 39d
<jumpfun+0x3d>
     39d:       48 89 df                mov    %rbx,%rdi
     3a0:       44 89 75 00             mov    %r14d,0x0(%rbp)
     3a4:       4c 89 20                mov    %r12,(%rax)
     3a7:       48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 3ae
<jumpfun+0x4e>
     3ae:       48 89 18                mov    %rbx,(%rax)
     3b1:       e8 00 00 00 00          callq  3b6 <jumpfun+0x56>
     3b6:       48 8d 7b 10             lea    0x10(%rbx),%rdi
     3ba:       44 89 ee                mov    %r13d,%esi
     3bd:       e8 00 00 00 00          callq  3c2 <jumpfun+0x62>
     3c2:       66 66 66 66 66 66 2e    data32 data32 data32 data32 data32 nopw
%cs:0x0(%rax,%rax,1)
     3c9:       0f 1f 84 00 00 00 00
     3d0:       00
     3d1:       66 66 66 66 66 66 2e    data32 data32 data32 data32 data32 nopw
%cs:0x0(%rax,%rax,1)
     3d8:       0f 1f 84 00 00 00 00
     3df:       00

with a SIGSEGV on 0x32c, while with -O -mtune=bdver2 compiles correctly to

000000000000228 <jumpfun>:
     228:       41 56                   push   %r14
     22a:       41 55                   push   %r13
     22c:       41 54                   push   %r12
     22e:       55                      push   %rbp
     22f:       53                      push   %rbx
     230:       48 89 fb                mov    %rdi,%rbx
     233:       41 89 f5                mov    %esi,%r13d
     236:       48 89 d5                mov    %rdx,%rbp
     239:       4c 8b 25 00 00 00 00    mov    0x0(%rip),%r12        # 240
<jumpfun+0x18>
     240:       45 8b 34 24             mov    (%r12),%r14d
     244:       48 89 d7                mov    %rdx,%rdi
     247:       e8 00 00 00 00          callq  24c <jumpfun+0x24>
     24c:       48 89 df                mov    %rbx,%rdi
     24f:       e8 00 00 00 00          callq  254 <jumpfun+0x2c>
     254:       bf 01 00 00 00          mov    $0x1,%edi
     259:       e8 00 00 00 00          callq  25e <jumpfun+0x36>
     25e:       45 89 34 24             mov    %r14d,(%r12)
     262:       48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 269
<jumpfun+0x41>
     269:       48 89 28                mov    %rbp,(%rax)
     26c:       48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 273
<jumpfun+0x4b>
     273:       48 89 18                mov    %rbx,(%rax)
     276:       48 89 df                mov    %rbx,%rdi
     279:       e8 00 00 00 00          callq  27e <jumpfun+0x56>
     27e:       48 8d 7b 10             lea    0x10(%rbx),%rdi
     282:       44 89 ee                mov    %r13d,%esi
     285:       e8 00 00 00 00          callq  28a <Rf_begincontext>

which works.

Gcc 4.7 compiled with "./configure --prefix=/usr/local/pkg/gcc-4.7.0
-program-suffix=4.7"

R compiled with

CC=gcc-4.7                    \
CXX=g++-4.7                   \
OBJC=gcc-4.7                  \
FC=gfortran-4.7               \
F77=gfortran-4.7              \
CFLAGS="-O3  -mtune=bdver2"    \
CXXFLAGS="-O3  -mtune=bdver2"  \
OBJCFLAGS="-O3  -mtune=bdver2" \
FCFLAGS="-O3  -mtune=bdver2"   \
FFLAGS="-O3  -mtune=bdver2"    \
./configure                   \
--enable-R-shlib              \
--enable-threads=posix        \
--with-readline               \
--with-system-pcre            \
--prefix=/usr/local/pkg/R-2.15.0-k15 \
--with-x                      \
--with-system-zlib            \
--with-cairo                  \
--with-jpeglib                \
--with-blas                   \
--with-lapack                 \
--with-tcltk                  \
--with-libpng


Thanks,

Valerio

---
Valerio Aimale
Chief, Advanced Projects
Qforma
http://www.qforma.com


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

end of thread, other threads:[~2012-05-16  6:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-15 15:38 [Bug c/53362] New: gcc 4.7 generates invalid code with -O3 and -mtune=bdver2 valerio at aimale dot com
2012-05-15 17:49 ` [Bug target/53362] " pinskia at gcc dot gnu.org
2012-05-15 19:02 ` valerio at aimale dot com
2012-05-15 22:15 ` valerio at aimale dot com
2012-05-15 22:24 ` valerio at aimale dot com
2012-05-16  6:31 ` ubizjak at gmail dot com

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).