https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99048
Bug ID: 99048
Summary: __gcc_qadd produces spurious NaN
Product: gcc
Version: 10.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libgcc
Assignee: unassigned at gcc dot gnu.org
Reporter: bbarenblat at gmail dot com
Target Milestone: ---
Target: powerpc64le-linux-gnu
Created attachment 50160
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50160&action=edit
minimal example
__gcc_qadd, which adds two long doubles on POWER, can emit NaN for non-NaN
input:
$ cat ldbl.c
extern int printf(const char* restrict, ...);
int main() {
long double a = -0x1.1e282e024debdb875f47f6c85p+1021L;
printf("%Le\n", a + 0x1.fffffffffffff7ffffffffffff8p+1023L);
}
$ gcc -O0 -o ldbl ldbl.c
$ ./ldbl
nan
$ gcc -O1 -o ldbl ldbl.c
$ ./ldbl
1.546510e+308
Examining the assembly from the second invocation shows that GCC has optimized
out the entire computation. In the first invocation, however, the compiled
program calls __gcc_qadd, which yields NaN. By IEEE 754, adding two non-NaN
inputs should never produce a NaN output.
Output of 'gcc -v':
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/powerpc64le-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: powerpc64le-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 10.2.1-6'
--with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-10
--program-prefix=powerpc64le-linux-gnu- --enable-shared
--enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap
--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-secureplt
--with-cpu=power8 --enable-targets=powerpcle-linux --disable-multilib
--enable-multiarch --disable-werror --with-long-double-128
--enable-offload-targets=nvptx-none=/build/gcc-10-jGDcMs/gcc-10-10.2.1/debian/tmp-nvptx/usr
--without-cuda-driver --enable-checking=release --build=powerpc64le-linux-gnu
--host=powerpc64le-linux-gnu --target=powerpc64le-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-mutex
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.1 20210110 (Debian 10.2.1-6)