Re: Optimization bug with floating-point?

From: Steve Kargl <sgk_at_troutmask.apl.washington.edu>
Date: Wed, 13 Mar 2019 11:16:23 -0700
On Wed, Mar 13, 2019 at 10:40:28AM -0700, Conrad Meyer wrote:
> Hi John,
> 
> On Wed, Mar 13, 2019 at 10:17 AM John Baldwin <jhb_at_freebsd.org> wrote:
> > One issue I'm aware of is that clang does not have any support for the
> > special arrangement FreeBSD/i386 uses where it uses different precision
> > for registers vs in-memory for some of the floating point types (GCC has
> > a special hack that is only used on FreeBSD for this but isn't used on
> > any other OS's).  I wonder if that could be a factor?  Volatile probably
> > forces a round trip between memory which might explain why this is the
> > case.
> >
> > I wonder what your test program does on i386 Linux with GCC?
> 
> $ uname -sr
> Linux 4.20.4
> $ gcc --version
> gcc (GCC) 8.2.1 20181215 (Red Hat 8.2.1-6)
> ...
> $ rpm -qf /usr/lib/libm-2.27.so
> glibc-2.27-37.fc28.i686
> 
> $ gcc -m32 -fno-builtin -o z kargl.c -lm && ./z
> Max ULP: 1.959975
> Count: 0
> $ gcc -O -m32 -fno-builtin -o z kargl.c -lm && ./z
> Max ULP: 1.959975
> Count: 0
> $ gcc -O1 -m32 -fno-builtin -o z kargl.c -lm && ./z
> Max ULP: 1.959975
> Count: 0
> $ gcc -O2 -m32 -fno-builtin -o z kargl.c -lm && ./z
> Max ULP: nan
> Count: 0
> $ gcc -O3 -m32 -fno-builtin -o z kargl.c -lm && ./z
> Max ULP: nan
> Count: 0
> 
> Uh.
> 
> kargl.c: In function ‘main’:
> kargl.c:80:10: warning: ‘u’ may be used uninitialized in this function
> [-Wmaybe-uninitialized]
>        if (ur > u) u = ur;
>           ^

Whoops.  There are a number of variations on a theme named a.c.
Initializing u to 0 doesn't change the outcome with clang on
FreeBSD.

-- 
Steve
Received on Wed Mar 13 2019 - 17:16:26 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:20 UTC