--- Begin Message ---
- To: Debian Bug Tracking System <submit@bugs.debian.org>
- Subject: gcc-4.8: [arm64] float to double conversion does not silence sNaN
- From: Aurelien Jarno <aurel32@debian.org>
- Date: Sat, 07 Jun 2014 12:49:45 +0200
- Message-id: <20140607104944.2780.85240.reportbug@arm64.rr44.fr>
Package: gcc-4.8
Version: 4.8.3-2
Severity: normal
Forwarded: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61441
Consider the following code:
#define _GNU_SOURCE
#include <stdio.h>
#include <math.h>
int main (void)
{
float sNaN = __builtin_nansf ("");
double x = (double) sNaN;
return issignaling(x);
}
It correctly returns 0 at -O0 optimisation level, but returns 1 at -O1
and -O2 optimisation levels.
Here is the generated assembly code at -O0:
0000000000400630 <main>:
400630: a9be7bfd stp x29, x30, [sp,#-32]!
400634: 910003fd mov x29, sp
400638: 18000160 ldr w0, 400664 <main+0x34>
40063c: b9001fa0 str w0, [x29,#28]
400640: b9401fa0 ldr w0, [x29,#28]
400644: 1e270000 fmov s0, w0
400648: 1e22c000 fcvt d0, s0
40064c: 9e660000 fmov x0, d0
400650: f9000ba0 str x0, [x29,#16]
400654: fd400ba0 ldr d0, [x29,#16]
400658: 97ffff8e bl 400490 <__issignaling@plt>
40065c: a8c27bfd ldp x29, x30, [sp],#32
400660: d65f03c0 ret
400664: 7fa00000 .word 0x7fa00000
Here is the generated assembly code at -O1:
0000000000400630 <main>:
400630: a9bf7bfd stp x29, x30, [sp,#-16]!
400634: 910003fd mov x29, sp
400638: 5c000080 ldr d0, 400648 <main+0x18>
40063c: 97ffff95 bl 400490 <__issignaling@plt>
400640: a8c17bfd ldp x29, x30, [sp],#16
400644: d65f03c0 ret
400648: 00000000 .word 0x00000000
40064c: 7ff40000 .word 0x7ff40000
As you can see at -O1, the sNaN constant is propagated, and the
propagated value is loaded and passed directly to issignaling.
Quoting the IEEE Std 754 standard:
"Under default exception handling, any operation signaling an invalid
operation exception and for which a floating-point result is to be
delivered shall deliver a quiet NaN."
So it looks like the copy propagation is not done correctly, the
sNaN should be silenced in the process.
Note: gcc-4.9 is also affected.
-- System Information:
Debian Release: jessie/sid
APT prefers unreleased
APT policy: (500, 'unreleased'), (500, 'unstable')
Architecture: arm64 (aarch64)
Kernel: Linux 3.15.0-5-generic (SMP w/1 CPU core)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages gcc-4.8 depends on:
ii binutils 2.24.51.20140604-2
ii cpp-4.8 4.8.3-2
ii gcc-4.8-base 4.8.3-2
ii libc6 2.18-7
ii libcloog-isl4 0.18.2-1
ii libgcc-4.8-dev 4.8.3-2
ii libgmp10 2:6.0.0+dfsg-4
ii libisl10 0.12.2-1
ii libmpc3 1.0.1-1
ii libmpfr4 3.1.2-1
ii zlib1g 1:1.2.8.dfsg-1
Versions of packages gcc-4.8 recommends:
ii libc6-dev 2.18-7
Versions of packages gcc-4.8 suggests:
pn gcc-4.8-doc <none>
pn gcc-4.8-locales <none>
pn libasan0-dbg <none>
pn libatomic1-dbg <none>
pn libbacktrace1-dbg <none>
pn libgcc1-dbg <none>
pn libgomp1-dbg <none>
pn libitm1-dbg <none>
pn libquadmath-dbg <none>
pn libtsan0-dbg <none>
-- no debconf information
--- End Message ---