Bug 64540 - [4.9 regression] Casting to/from long double emits ambiguous fild/fisttp instruction
Summary: [4.9 regression] Casting to/from long double emits ambiguous fild/fisttp inst...
Status: RESOLVED DUPLICATE of bug 66509
Alias: None
Product: gcc
Classification: Unclassified
Component: driver (show other bugs)
Version: 4.9.2
: P3 normal
Target Milestone: 4.9.4
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-08 14:27 UTC by zan
Modified: 2015-06-26 21:07 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.8.3
Known to fail: 4.9.2
Last reconfirmed:


Attachments
Minimal code example (523 bytes, text/plain)
2015-01-08 14:27 UTC, zan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description zan 2015-01-08 14:27:14 UTC
Created attachment 34401 [details]
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:
Comment 1 Jakub Jelinek 2015-01-08 14:41:29 UTC
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.
Comment 2 zan 2015-01-13 18:11:02 UTC
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).
Comment 3 Jakub Jelinek 2015-06-26 19:55:22 UTC
GCC 4.9.3 has been released.
Comment 4 Andrew Pinski 2015-06-26 21:07:50 UTC
This is not a regression.

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