public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug driver/64540] New: [4.9 regression] Casting to/from long double emits ambiguous fild/fisttp instruction
@ 2015-01-08 14:27 zanpeeters at gmail dot com
  2015-01-08 14:41 ` [Bug driver/64540] " jakub at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: zanpeeters at gmail dot com @ 2015-01-08 14:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64540

            Bug ID: 64540
           Summary: [4.9 regression] Casting to/from long double emits
                    ambiguous fild/fisttp instruction
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: driver
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zanpeeters at gmail dot com

Created attachment 34401
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34401&action=edit
Minimal code example

GCC 4.9.2 emits a fild instruction for a cast of signed char, unsigned char, or
signed short (but not unsigned short) to long double. For the reverse cast a
fisttp instruction is emitted.

Minimal code example:

int main()
{
  unsigned char a = 0;
  long double d = 0.0;

  d = (long double)a;

  return 0;
}

On a Mac, compiling this minimal code with -Wa,-q (send -q to the assembler,
which then uses the clang built in assembler rather than as) generates the
following error:

> gcc -Wa,-q minexmpl.c
/var/folders/Dc/DcfDPTBiHROi8AvxZY9-HE+++TI/-Tmp-//cc7UuOqP.s:16:2: error:
ambiguous instructions require an explicit suffix (could be 'filds', or
'fildl')
        fild    -34(%rbp)

GCC 4.8.3 emits filds/fisttps instructions for the same code and does not
generate an error when send to the clang assembler. Since GCC 4.8.3 emitted the
correct instructions this seems a regression to me. Any particular reason this
change was made?

Attached is a complete minimal code example with all casting combinations that
lead to errors. On any OS (also non-Mac):

> gcc-4.9 -S -o out49.s fild_fisttp.c
> gcc-4.8 -S -o out48.s fild_fisttp.c
> diff -u out48.s out49.s
--- out48.s
+++ out49.s
@@ -14,25 +14,25 @@
    fstpt       -32(%rbp)
-   filds       -4(%rbp)
+   fild        -4(%rbp)
    fstpt       -32(%rbp)
    fldt        -32(%rbp)
-   fisttps     -34(%rbp)
+   fisttp      -34(%rbp)
    movzwl      -34(%rbp), %eax
(truncated for brevity, full diff below)

Note 1:
Not accepting fild, fisttp, and others is a design choice by LLVM, see
http://clang.llvm.org/compatibility.html#inline-asm  I have tested the above
minimal code example with Apple clang 3.0/XCode 4.2, Macports clang 3.3, and
Macports clang 3.5 and all give the same result.

Note 2:
The reason for using the clang assembler is that the as assembler on Mac is
very old and does not accept AVX or newer instructions, as explained here:
https://stackoverflow.com/questions/9840207/how-to-use-avx-pclmulqdq-on-mac-os-x-lion

=====================

Other information:

System: Mac OS X 10.6.8

gcc version 4.9.2 (MacPorts gcc49 4.9.2_1)
Using built-in specs.
COLLECT_GCC=gcc-mp-4.9
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin10/4.9.2/lto-wrapper
Target: x86_64-apple-darwin10
Configured with:
/opt/local/var/macports/build/_Users_zan_Library_Macports_lang_gcc49/gcc49/work/gcc-4.9.2/configure
--prefix=/opt/local --disable-silent-rules --build=x86_64-apple-darwin10
--enable-languages=c,c++,objc,obj-c++,lto,fortran,java
--libdir=/opt/local/lib/gcc49 --includedir=/opt/local/include/gcc49
--infodir=/opt/local/share/info --mandir=/opt/local/share/man
--datarootdir=/opt/local/share/gcc-4.9 --with-local-prefix=/opt/local
--with-system-zlib --disable-nls --program-suffix=-mp-4.9
--with-gxx-include-dir=/opt/local/include/gcc49/c++/ --with-gmp=/opt/local
--with-mpfr=/opt/local --with-mpc=/opt/local --with-isl=/opt/local
--disable-isl-version-check --with-cloog=/opt/local
--disable-cloog-version-check --enable-stage1-checking --disable-multilib
--enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as
--with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar
--with-bugurl=https://trac.macports.org/newticket --with-pkgversion='MacPorts
gcc49 4.9.2_1'
Thread model: posix

gcc version 4.8.3 (MacPorts gcc48 4.8.3_2)
COLLECT_GCC=gcc-mp-4.8
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin10/4.8.3/lto-wrapper
Target: x86_64-apple-darwin10
Configured with:
/opt/local/var/macports/build/_Users_zan_Library_Macports_lang_gcc48/gcc48/work/gcc-4.8.3/configure
--prefix=/opt/local --disable-silent-rules --build=x86_64-apple-darwin10
--enable-languages=c,c++,objc,obj-c++,lto,fortran,java
--libdir=/opt/local/lib/gcc48 --includedir=/opt/local/include/gcc48
--infodir=/opt/local/share/info --mandir=/opt/local/share/man
--datarootdir=/opt/local/share/gcc-4.8 --with-local-prefix=/opt/local
--with-system-zlib --disable-nls --program-suffix=-mp-4.8
--with-gxx-include-dir=/opt/local/include/gcc48/c++/ --with-gmp=/opt/local
--with-mpfr=/opt/local --with-mpc=/opt/local --with-cloog=/opt/local
--enable-cloog-backend=isl --disable-cloog-version-check
--disable-isl-version-check --enable-stage1-checking --disable-multilib
--enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as
--with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar
--with-bugurl=https://trac.macports.org/newticket --with-pkgversion='MacPorts
gcc48 4.8.3_2'
Thread model: posix

==========================
Diff output

--- fild_fisttp48.s    2015-01-08 19:21:11.000000000 +0000
+++ fild_fisttp49.s    2015-01-08 19:20:50.000000000 +0000
@@ -14,25 +14,25 @@
     movq    %rax, -32(%rbp)
     movl    %edx, -24(%rbp)
     movzbl    -1(%rbp), %eax
-    movw    %ax, -34(%rbp)
-    filds    -34(%rbp)
+    movw    %ax, -36(%rbp)
+    fild    -36(%rbp)
     fstpt    -32(%rbp)
     movsbw    -2(%rbp), %ax
-    movw    %ax, -34(%rbp)
-    filds    -34(%rbp)
+    movw    %ax, -36(%rbp)
+    fild    -36(%rbp)
     fstpt    -32(%rbp)
-    filds    -4(%rbp)
+    fild    -4(%rbp)
     fstpt    -32(%rbp)
     fldt    -32(%rbp)
-    fisttps    -34(%rbp)
+    fisttp    -34(%rbp)
     movzwl    -34(%rbp), %eax
     movb    %al, -1(%rbp)
     fldt    -32(%rbp)
-    fisttps    -34(%rbp)
+    fisttp    -34(%rbp)
     movzwl    -34(%rbp), %eax
     movb    %al, -2(%rbp)
     fldt    -32(%rbp)
-    fisttps    -4(%rbp)
+    fisttp    -4(%rbp)
     movl    $0, %eax
     popq    %rbp
 LCFI2:


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

* [Bug driver/64540] [4.9 regression] Casting to/from long double emits ambiguous fild/fisttp instruction
  2015-01-08 14:27 [Bug driver/64540] New: [4.9 regression] Casting to/from long double emits ambiguous fild/fisttp instruction zanpeeters at gmail dot com
@ 2015-01-08 14:41 ` jakub at gcc dot gnu.org
  2015-01-09 11:32 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-01-08 14:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64540

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Sounds like user error to me.
This is nothing that changed in between 4.8 and 4.9, but depends on against
which assembler you configure gcc.  If you configure it against old assembler
that doesn't accept filds/fists instructions, then it will emit fild, otherwise
it emits filds.  Similarly, if assembler doesn't accept fildq/fistpq
instruction, it will emit fildll.  This is checked during gcc configure.


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

* [Bug driver/64540] [4.9 regression] Casting to/from long double emits ambiguous fild/fisttp instruction
  2015-01-08 14:27 [Bug driver/64540] New: [4.9 regression] Casting to/from long double emits ambiguous fild/fisttp instruction zanpeeters at gmail dot com
  2015-01-08 14:41 ` [Bug driver/64540] " jakub at gcc dot gnu.org
@ 2015-01-09 11:32 ` rguenth at gcc dot gnu.org
  2015-01-13 18:11 ` zanpeeters at gmail dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-01-09 11:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64540

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.9.3


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

* [Bug driver/64540] [4.9 regression] Casting to/from long double emits ambiguous fild/fisttp instruction
  2015-01-08 14:27 [Bug driver/64540] New: [4.9 regression] Casting to/from long double emits ambiguous fild/fisttp instruction zanpeeters at gmail dot com
  2015-01-08 14:41 ` [Bug driver/64540] " jakub at gcc dot gnu.org
  2015-01-09 11:32 ` rguenth at gcc dot gnu.org
@ 2015-01-13 18:11 ` zanpeeters at gmail dot com
  2015-06-26 20:02 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: zanpeeters at gmail dot com @ 2015-01-13 18:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64540

--- Comment #2 from zan <zanpeeters at gmail dot com> ---
Thank you for the info. I tried recompiling gcc 4.9.2 and found in
build/gcc/config.log:

configure:24745: checking assembler for filds and fists mnemonics
configure:24754: /opt/local/bin/as    -o conftest.o conftest.s >&5
clang -cc1as: fatal error: error in backend: 32-bit absolute addressing is not
supported in 64-bit mode
configure:24757: $? = 1
configure: failed program was
filds mem; fists mem
configure:24768: result: no
configure:24776: checking assembler for fildq and fistpq mnemonics
configure:24785: /opt/local/bin/as    -o conftest.o conftest.s >&5
clang -cc1as: fatal error: error in backend: 32-bit absolute addressing is not
supported in 64-bit mode
configure:24788: $? = 1
configure: failed program was
fildq mem; fistpq mem
configure:24799: result: no

/opt/local/bin/as is a wrapper script that calls either clang integrated-as or
regular as.

If I run the regular as assembler on "filds mem; fists mem":
tmp.s:1:32-bit absolute addressing is not supported for x86-64
tmp.s:1:cannot do signed 4 byte relocation
tmp.s:1:32-bit absolute addressing is not supported for x86-64
tmp.s:1:cannot do signed 4 byte relocation

So it's not about the choice of assembler. If I change mem to something like
0(%rax), both commands complete without error. I don't know enough about
assembly to understand what's going on, but gcc build completes and the minimal
example compiles without error (assembly uses filds).

This seems to be a Mac OS X specific problem
(https://stackoverflow.com/questions/26394359/mach-o-64-bit-format-does-not-support-32-bit-absolute-addresses-nasm).


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

* [Bug driver/64540] [4.9 regression] Casting to/from long double emits ambiguous fild/fisttp instruction
  2015-01-08 14:27 [Bug driver/64540] New: [4.9 regression] Casting to/from long double emits ambiguous fild/fisttp instruction zanpeeters at gmail dot com
                   ` (2 preceding siblings ...)
  2015-01-13 18:11 ` zanpeeters at gmail dot com
@ 2015-06-26 20:02 ` jakub at gcc dot gnu.org
  2015-06-26 20:32 ` jakub at gcc dot gnu.org
  2015-06-26 21:21 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-06-26 20:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64540

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 4.9.3 has been released.


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

* [Bug driver/64540] [4.9 regression] Casting to/from long double emits ambiguous fild/fisttp instruction
  2015-01-08 14:27 [Bug driver/64540] New: [4.9 regression] Casting to/from long double emits ambiguous fild/fisttp instruction zanpeeters at gmail dot com
                   ` (3 preceding siblings ...)
  2015-06-26 20:02 ` jakub at gcc dot gnu.org
@ 2015-06-26 20:32 ` jakub at gcc dot gnu.org
  2015-06-26 21:21 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-06-26 20:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64540

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.9.3                       |4.9.4


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

* [Bug driver/64540] [4.9 regression] Casting to/from long double emits ambiguous fild/fisttp instruction
  2015-01-08 14:27 [Bug driver/64540] New: [4.9 regression] Casting to/from long double emits ambiguous fild/fisttp instruction zanpeeters at gmail dot com
                   ` (4 preceding siblings ...)
  2015-06-26 20:32 ` jakub at gcc dot gnu.org
@ 2015-06-26 21:21 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-06-26 21:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64540

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is not a regression.

*** This bug has been marked as a duplicate of bug 66509 ***


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

end of thread, other threads:[~2015-06-26 21:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-08 14:27 [Bug driver/64540] New: [4.9 regression] Casting to/from long double emits ambiguous fild/fisttp instruction zanpeeters at gmail dot com
2015-01-08 14:41 ` [Bug driver/64540] " jakub at gcc dot gnu.org
2015-01-09 11:32 ` rguenth at gcc dot gnu.org
2015-01-13 18:11 ` zanpeeters at gmail dot com
2015-06-26 20:02 ` jakub at gcc dot gnu.org
2015-06-26 20:32 ` jakub at gcc dot gnu.org
2015-06-26 21:21 ` pinskia at gcc dot gnu.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).