public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/38922]  New: Optimization regression in simple conditional code (js instead of cmov) 4.3 vs 4.1 and 3.4
@ 2009-01-20  8:45 vincenzo dot innocente at cern dot ch
  2009-01-20  8:48 ` [Bug c/38922] " vincenzo dot innocente at cern dot ch
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: vincenzo dot innocente at cern dot ch @ 2009-01-20  8:45 UTC (permalink / raw)
  To: gcc-bugs

I discovered that a simple benchmark ("SCIMARK2 Montecarlo") runs tree times
slower when compiled with gcc 4.3 w.r.t. 4.1 or 3.4
Code is compiled and run of INTEL core 2 machines running RHEL4, RHEL5 or
fedora10.
below details on fedora 10
compilers used are from fedora distribution
-bash-3.2$ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib
--with-cpu=generic --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC)

-bash-3.2$ gcc34 -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-languages=c,c++,f77 --disable-libgcj
--host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-9)


I've extracted the code in a self contained source downloadable from
wget http://innocent.home.cern.ch/innocent/fullMC.c
results are
-bash-3.2$ g++ -O3 fullMC.c ; time ./a.out 

real    0m1.731s
user    0m1.730s
sys     0m0.001s
-bash-3.2$ g++34 -O3 fullMC.c ; time ./a.out 

real    0m0.547s
user    0m0.546s
sys     0m0.001s


in my opinion the culprit is a wrong use of jump instead of cmov instruction
here:

this is the disassember emitted by 4.3

  int I = R->i;
 400510:       8b 4f 48                mov    0x48(%rdi),%ecx
   int J = R->j;
 400513:       8b 77 4c                mov    0x4c(%rdi),%esi
   int *m = R->m;

   k = m[I] - m[J];
 400516:       48 63 c1                movslq %ecx,%rax
 400519:       48 63 d6                movslq %esi,%rdx
 40051c:       8b 04 87                mov    (%rdi,%rax,4),%eax
   if (k < 0) k += m1;
 40051f:       41 89 c0                mov    %eax,%r8d
 400522:       44 2b 04 97             sub    (%rdi,%rdx,4),%r8d
 400526:       78 58                   js     400580 <Random_nextDouble+0x70>
   R->m[J] = k;


and this for 3.4

   int I = R->i;
 400660:       8b 47 48                mov    0x48(%rdi),%eax
   int J = R->j;
 400663:       8b 57 4c                mov    0x4c(%rdi),%edx
   int *m = R->m;

   k = m[I] - m[J];
 400666:       48 63 c8                movslq %eax,%rcx
 400669:       48 63 f2                movslq %edx,%rsi
 40066c:       44 8b 04 8f             mov    (%rdi,%rcx,4),%r8d
 400670:       44 2b 04 b7             sub    (%rdi,%rsi,4),%r8d
   if (k < 0) k += m1;
 400674:       41 8d 88 ff ff ff 7f    lea    0x7fffffff(%r8),%ecx
 40067b:       41 83 f8 ff             cmp    $0xffffffffffffffff,%r8d
 40067f:       44 0f 4e c1             cmovle %ecx,%r8d
   R->m[J] = k;
-------------------------------------

gcc 4.1 (below specs from RHL5) produces same instructions than 3.4

 gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic
--host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)


-- 
           Summary: Optimization regression in simple conditional code (js
                    instead of cmov) 4.3 vs 4.1 and 3.4
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vincenzo dot innocente at cern dot ch
 GCC build triplet: x86_64-redhat-linux
  GCC host triplet: x86_64-redhat-linux
GCC target triplet: x86_64-redhat-linux


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


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

* [Bug c/38922] Optimization regression in simple conditional code (js instead of cmov) 4.3 vs 4.1 and 3.4
  2009-01-20  8:45 [Bug c/38922] New: Optimization regression in simple conditional code (js instead of cmov) 4.3 vs 4.1 and 3.4 vincenzo dot innocente at cern dot ch
@ 2009-01-20  8:48 ` vincenzo dot innocente at cern dot ch
  2009-01-20  9:04 ` [Bug c/38922] [4.3 Regression] " rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: vincenzo dot innocente at cern dot ch @ 2009-01-20  8:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from vincenzo dot innocente at cern dot ch  2009-01-20 08:48 -------
Created an attachment (id=17152)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17152&action=view)
test case


-- 


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


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

* [Bug c/38922] [4.3 Regression] Optimization regression in simple conditional code (js instead of cmov) 4.3 vs 4.1 and 3.4
  2009-01-20  8:45 [Bug c/38922] New: Optimization regression in simple conditional code (js instead of cmov) 4.3 vs 4.1 and 3.4 vincenzo dot innocente at cern dot ch
  2009-01-20  8:48 ` [Bug c/38922] " vincenzo dot innocente at cern dot ch
@ 2009-01-20  9:04 ` rguenth at gcc dot gnu dot org
  2009-01-20  9:24 ` vincenzo dot innocente at cern dot ch
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-01-20  9:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2009-01-20 09:04 -------
4.4.0 is faster for me than 4.2 and 4.3 (4.3 is indeed slower than 4.2, but
my 3.4 (32bit only) is way slower than 4.4 (also 32bit)).

Note that performance of cmov heavily depends on the microarchitecture of your
CPU (I measured on a AMD K8).


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
      Known to fail|                            |4.3.2
      Known to work|                            |3.4.6 4.4.0
            Summary|Optimization regression in  |[4.3 Regression]
                   |simple conditional code (js |Optimization regression in
                   |instead of cmov) 4.3 vs 4.1 |simple conditional code (js
                   |and 3.4                     |instead of cmov) 4.3 vs 4.1
                   |                            |and 3.4
   Target Milestone|---                         |4.3.3


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


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

* [Bug c/38922] [4.3 Regression] Optimization regression in simple conditional code (js instead of cmov) 4.3 vs 4.1 and 3.4
  2009-01-20  8:45 [Bug c/38922] New: Optimization regression in simple conditional code (js instead of cmov) 4.3 vs 4.1 and 3.4 vincenzo dot innocente at cern dot ch
  2009-01-20  8:48 ` [Bug c/38922] " vincenzo dot innocente at cern dot ch
  2009-01-20  9:04 ` [Bug c/38922] [4.3 Regression] " rguenth at gcc dot gnu dot org
@ 2009-01-20  9:24 ` vincenzo dot innocente at cern dot ch
  2009-01-24 10:28 ` [Bug target/38922] " rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: vincenzo dot innocente at cern dot ch @ 2009-01-20  9:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from vincenzo dot innocente at cern dot ch  2009-01-20 09:24 -------
I confirm that gcc 4.2.3 is as fast as 4.1 and at least twice as slow of gcc
4.3.2
test done on an intel core2 running RHL4 and core i7 with RHL5.
mtune either generic or native (no difference)


-- 


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


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

* [Bug target/38922] [4.3 Regression] Optimization regression in simple conditional code (js instead of cmov) 4.3 vs 4.1 and 3.4
  2009-01-20  8:45 [Bug c/38922] New: Optimization regression in simple conditional code (js instead of cmov) 4.3 vs 4.1 and 3.4 vincenzo dot innocente at cern dot ch
                   ` (2 preceding siblings ...)
  2009-01-20  9:24 ` vincenzo dot innocente at cern dot ch
@ 2009-01-24 10:28 ` rguenth at gcc dot gnu dot org
  2009-02-21 13:13 ` rguenth at gcc dot gnu dot org
  2009-04-22 15:21 ` rguenth at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-01-24 10:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2009-01-24 10:21 -------
GCC 4.3.3 is being released, adjusting target milestone.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.3.3                       |4.3.4


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


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

* [Bug target/38922] [4.3 Regression] Optimization regression in simple conditional code (js instead of cmov) 4.3 vs 4.1 and 3.4
  2009-01-20  8:45 [Bug c/38922] New: Optimization regression in simple conditional code (js instead of cmov) 4.3 vs 4.1 and 3.4 vincenzo dot innocente at cern dot ch
                   ` (3 preceding siblings ...)
  2009-01-24 10:28 ` [Bug target/38922] " rguenth at gcc dot gnu dot org
@ 2009-02-21 13:13 ` rguenth at gcc dot gnu dot org
  2009-04-22 15:21 ` rguenth at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-02-21 13:13 UTC (permalink / raw)
  To: gcc-bugs



-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2


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


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

* [Bug target/38922] [4.3 Regression] Optimization regression in simple conditional code (js instead of cmov) 4.3 vs 4.1 and 3.4
  2009-01-20  8:45 [Bug c/38922] New: Optimization regression in simple conditional code (js instead of cmov) 4.3 vs 4.1 and 3.4 vincenzo dot innocente at cern dot ch
                   ` (4 preceding siblings ...)
  2009-02-21 13:13 ` rguenth at gcc dot gnu dot org
@ 2009-04-22 15:21 ` rguenth at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-04-22 15:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2009-04-22 15:21 -------
WONTFIX on the 4.3 branch.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
      Known to fail|4.3.2                       |4.3.2 4.3.3
         Resolution|                            |FIXED
   Target Milestone|4.3.4                       |4.4.0


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


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

end of thread, other threads:[~2009-04-22 15:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-20  8:45 [Bug c/38922] New: Optimization regression in simple conditional code (js instead of cmov) 4.3 vs 4.1 and 3.4 vincenzo dot innocente at cern dot ch
2009-01-20  8:48 ` [Bug c/38922] " vincenzo dot innocente at cern dot ch
2009-01-20  9:04 ` [Bug c/38922] [4.3 Regression] " rguenth at gcc dot gnu dot org
2009-01-20  9:24 ` vincenzo dot innocente at cern dot ch
2009-01-24 10:28 ` [Bug target/38922] " rguenth at gcc dot gnu dot org
2009-02-21 13:13 ` rguenth at gcc dot gnu dot org
2009-04-22 15:21 ` rguenth at gcc dot gnu dot org

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