public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/39116]  New: wrong register used when generating assembly with -O1
@ 2009-02-06  1:47 fabrice at mocana dot com
  2009-02-06  1:50 ` [Bug inline-asm/39116] " fabrice at mocana dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: fabrice at mocana dot com @ 2009-02-06  1:47 UTC (permalink / raw)
  To: gcc-bugs

The inline assembly can end up generating instructions of the form 
mulq %rax when the two operands should be distinct (i.e. one should not compute
%rax * %rax, a square but a product of two different numbers).(The x86 mulq
instruction will compute the product of the operand with the %rax register).
This happens with -O1 and any higher level of optimizations.

Version information:

gcc -m64 -c -O1 -v -save-temps gnu_bug_test.c
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr
--with-local-prefix=/usr/local --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,obj-c++,java,ada
--enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.2.1
--enable-ssp --disable-libssp --disable-libgcj --with-slibdir=/lib64
--with-system-zlib --enable-shared --enable-__cxa_atexit
--enable-libstdcxx-allocator=new --disable-libstdcxx-pch --program-suffix=-4.2
--enable-version-specific-runtime-libs --without-system-libunwind
--with-cpu=generic --host=x86_64-suse-linux
Thread model: posix
gcc version 4.2.1 (SUSE Linux)
 /usr/lib64/gcc/x86_64-suse-linux/4.2.1/cc1 -E -quiet -v gnu_bug_test.c -m64
-mtune=generic -O1 -fpch-preprocess -o gnu_bug_test.i
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib64/gcc/x86_64-suse-linux/4.2.1/include
 /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/include
 /usr/include
End of search list.
 /usr/lib64/gcc/x86_64-suse-linux/4.2.1/cc1 -fpreprocessed gnu_bug_test.i
-quiet -dumpbase gnu_bug_test.c -m64 -mtune=generic -auxbase gnu_bug_test -O1
-version -o gnu_bug_test.s
GNU C version 4.2.1 (SUSE Linux) (x86_64-suse-linux)
        compiled by GNU C version 4.2.1 (SUSE Linux).
GGC heuristics: --param ggc-min-expand=94 --param ggc-min-heapsize=120388
Compiler executable checksum: 15875aa798ad559dcc04a8709924cdb9
 /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/bin/as -V
-Qy --64 -o gnu_bug_test.o gnu_bug_test.s
GNU assembler version 2.17.50 (x86_64-suse-linux) using BFD version (GNU
Binutils) 2.17.50.20070726-14 (SUSE Linux)


-- 
           Summary: wrong register used when generating assembly with -O1
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fabrice at mocana dot com
 GCC build triplet: x86_64-suse-linux
  GCC host triplet: x86_64-suse-linux
GCC target triplet: x86_64-suse-linux


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


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

* [Bug inline-asm/39116] wrong register used when generating assembly with -O1
  2009-02-06  1:47 [Bug inline-asm/39116] New: wrong register used when generating assembly with -O1 fabrice at mocana dot com
@ 2009-02-06  1:50 ` fabrice at mocana dot com
  2009-02-06  1:51 ` fabrice at mocana dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: fabrice at mocana dot com @ 2009-02-06  1:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from fabrice at mocana dot com  2009-02-06 01:50 -------
Created an attachment (id=17257)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17257&action=view)
preprocessed file

Note that all multiplicands are distinct.


-- 


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


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

* [Bug inline-asm/39116] wrong register used when generating assembly with -O1
  2009-02-06  1:47 [Bug inline-asm/39116] New: wrong register used when generating assembly with -O1 fabrice at mocana dot com
  2009-02-06  1:50 ` [Bug inline-asm/39116] " fabrice at mocana dot com
@ 2009-02-06  1:51 ` fabrice at mocana dot com
  2009-02-06  1:58 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: fabrice at mocana dot com @ 2009-02-06  1:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from fabrice at mocana dot com  2009-02-06 01:51 -------
Created an attachment (id=17258)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17258&action=view)
generated assembly

note the mulq %rax instruction towards the end.


-- 


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


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

* [Bug inline-asm/39116] wrong register used when generating assembly with -O1
  2009-02-06  1:47 [Bug inline-asm/39116] New: wrong register used when generating assembly with -O1 fabrice at mocana dot com
  2009-02-06  1:50 ` [Bug inline-asm/39116] " fabrice at mocana dot com
  2009-02-06  1:51 ` fabrice at mocana dot com
@ 2009-02-06  1:58 ` pinskia at gcc dot gnu dot org
  2009-02-06  3:49 ` fabrice at mocana dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-02-06  1:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2009-02-06 01:58 -------
b[1] is uninitialized.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|wrong register used when    |wrong register used when
                   |generating assembly with -O1|generating assembly with -O1


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


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

* [Bug inline-asm/39116] wrong register used when generating assembly with -O1
  2009-02-06  1:47 [Bug inline-asm/39116] New: wrong register used when generating assembly with -O1 fabrice at mocana dot com
                   ` (2 preceding siblings ...)
  2009-02-06  1:58 ` pinskia at gcc dot gnu dot org
@ 2009-02-06  3:49 ` fabrice at mocana dot com
  2009-02-06  4:24 ` fabrice at mocana dot com
  2009-02-06 17:16 ` fabrice at mocana dot com
  5 siblings, 0 replies; 7+ messages in thread
From: fabrice at mocana dot com @ 2009-02-06  3:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from fabrice at mocana dot com  2009-02-06 03:48 -------
(In reply to comment #3)
> b[1] is uninitialized.

Yes, initializing b[1] makes the problem go away in the snippet. I see this
problem in a much larger program but I can't reproduce it in a simple context.
Feel free to close the bug as invalid since there's a workaround for it,
although it impacts performance.


-- 


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


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

* [Bug inline-asm/39116] wrong register used when generating assembly with -O1
  2009-02-06  1:47 [Bug inline-asm/39116] New: wrong register used when generating assembly with -O1 fabrice at mocana dot com
                   ` (3 preceding siblings ...)
  2009-02-06  3:49 ` fabrice at mocana dot com
@ 2009-02-06  4:24 ` fabrice at mocana dot com
  2009-02-06 17:16 ` fabrice at mocana dot com
  5 siblings, 0 replies; 7+ messages in thread
From: fabrice at mocana dot com @ 2009-02-06  4:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from fabrice at mocana dot com  2009-02-06 04:24 -------
(In reply to comment #4)
> Yes, initializing b[1] makes the problem go away in the snippet. I see this
> problem in a much larger program but I can't reproduce it in a simple context.
> Feel free to close the bug as invalid since there's a workaround for it,
> although it impacts performance.
More details on this: the problem happens only with -O3 in the large context.
The workaround is to add a movq %3, %%eax before doing the mulq %4. That's why
an invalid mul %eax was thought to be the problem. I thought the snippet
acurately reproduced the problem but it seems unlikely at this point.  


-- 


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


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

* [Bug inline-asm/39116] wrong register used when generating assembly with -O1
  2009-02-06  1:47 [Bug inline-asm/39116] New: wrong register used when generating assembly with -O1 fabrice at mocana dot com
                   ` (4 preceding siblings ...)
  2009-02-06  4:24 ` fabrice at mocana dot com
@ 2009-02-06 17:16 ` fabrice at mocana dot com
  5 siblings, 0 replies; 7+ messages in thread
From: fabrice at mocana dot com @ 2009-02-06 17:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from fabrice at mocana dot com  2009-02-06 17:16 -------
(In reply to comment #5)
Closing this as invalid. The problem is the interaction of the inline assembly
with the optimization option -funswitch-loops. Will submit a new bug if I can
find a simple way to reproduce it.


-- 

fabrice at mocana dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

end of thread, other threads:[~2009-02-06 17:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-06  1:47 [Bug inline-asm/39116] New: wrong register used when generating assembly with -O1 fabrice at mocana dot com
2009-02-06  1:50 ` [Bug inline-asm/39116] " fabrice at mocana dot com
2009-02-06  1:51 ` fabrice at mocana dot com
2009-02-06  1:58 ` pinskia at gcc dot gnu dot org
2009-02-06  3:49 ` fabrice at mocana dot com
2009-02-06  4:24 ` fabrice at mocana dot com
2009-02-06 17:16 ` fabrice at mocana 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).