[Bug c/17394] New: Implicit SSE/SSE2 FP code reordering in Placement Independent Code error (SSE/optimisation/PIC)
ivan at vmfacility dot fr
gcc-bugzilla@gcc.gnu.org
Fri Sep 10 12:30:00 GMT 2004
Here is a simple code :
<testcase>
#include <stdio.h>
float foo;
int main()
{
unsigned int y;
*((unsigned int *)&foo)=0x40555555;
y=(int)foo;
printf("%g %d\n",foo,y);
}
</testcase>
Note : Direct FP manipulation is required by my application as it needs to
perform conversion from a different FP encoding.
Straight compiling (gcc foo.c -o foo) gives the expected result :
"3.3333 3"
However, compiling with the following flags give various results :
"gcc -O3 -march=pentium4 -fPIC foo.c foo"
gives :
"0 0"
Using gcc 3.3.4 with the same flags give :
"3.3333 0"
Examination of the generated assembly indicate various cases :
Starting with 3.4.1 (comments are my own)
... prolog ...
movss (%ecx), %xmm0 Put *%ecx in MMX Reg 0
movl $1079334229, (%ecx) Put constant in *%ecx - UGH ! Backwards
subl $16, %esp
movss %xmm0, -8(%ebp) Save MMX Reg 0 in %ebp[-8]
cvttss2si %xmm0, %edx Convert Single Prec to Signed Int to %edx
movl %eax, (%esp)
flds -8(%ebp)
movl %edx, 12(%esp)
fstpl 4(%esp)
call printf@PLT
... epilog ...
and now with gcc 3.3.4 :
... prolog ...
cvttss2si (%ecx), %eax Convert Single Prec float @%ecx to %eax
movl $1079334229, (%ecx) Put constant value@%ecx - Backwards !
movl %eax, 12(%esp)
flds (%ecx)
movl %edx, (%esp)
fstpl 4(%esp)
call printf@PLT
... epilog ...
Notes
- No problem shows if -fPIC is not specified
- Tried -mfpmath=387 but didn't help
- -msse or -msse2 are also sufficient to trigger the problem
- with -march=pentium2 and no -msseX, the problem goes away
- Problem only shows at -O2 or better
I tried with
- gcc 3.3.4 from debian
- gcc 3.4.1 from debian
- gcc 3.4.1 from Mandrake
(haven't tried stock gcc - but I suspect I might be getting identical results
as I am getting similar results from different vendors).
Thanks,
--Ivan
--
Summary: Implicit SSE/SSE2 FP code reordering in Placement
Independent Code error (SSE/optimisation/PIC)
Product: gcc
Version: 3.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ivan at vmfacility dot fr
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-linux-gnu
GCC host triplet: i686-linux-gnu
GCC target triplet: i686-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17394
More information about the Gcc-bugs
mailing list