public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* linking time eroor with -fast-math -O0
@ 2011-08-26 12:52 Vladimir Yakovlev
  2011-08-26 12:55 ` Richard Guenther
  0 siblings, 1 reply; 2+ messages in thread
From: Vladimir Yakovlev @ 2011-08-26 12:52 UTC (permalink / raw)
  To: gcc

Hi,

Following test fails in linking if compiled with ffast-math and O0,
but it compiled successfully with ffast-math and O2. Also no problem
if -lm is added.

$ cat t.c
#include <stdio.h>

float foo(float x)
{
   float y = 0;
   while (x > 0.00000001) {
     y += x*x*x*x*x*x*x*x*x*x*x*x*x;
     x = x/2;
   }
   return y;
}

int main (int argc, char    *argv[])
{
  float y = atoi(argv[1]);
  printf("%f\n", foo(y));
  return 0;
}


$ gcc  -ffast-math -O0   t.c
/tmp/cccA1sUB.o: In function `foo':
t.c:(.text+0x2c): undefined reference to `powf'
collect2: error: ld returned 1 exit status
$ gcc  -ffast-math -O2   t.c
$ ./a.out 5
1220852096.000000


FE with -ffast-math replaced x*x*...*x with __builtin_powf. Later with
-O2 this call is replaced back into multiplications in sincos phase.
The stability with -O0 is because sincos phase doesn't work on -O0.

I think we must avoid doing this optimization in FE and turn off
-ffast-math if -O0 is used. Your opinion.

Thanks,
Vladimir

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

* Re: linking time eroor with -fast-math -O0
  2011-08-26 12:52 linking time eroor with -fast-math -O0 Vladimir Yakovlev
@ 2011-08-26 12:55 ` Richard Guenther
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Guenther @ 2011-08-26 12:55 UTC (permalink / raw)
  To: Vladimir Yakovlev; +Cc: gcc

On Fri, Aug 26, 2011 at 2:52 PM, Vladimir Yakovlev <vbyakovl23@gmail.com> wrote:
> Hi,
>
> Following test fails in linking if compiled with ffast-math and O0,
> but it compiled successfully with ffast-math and O2. Also no problem
> if -lm is added.
>
> $ cat t.c
> #include <stdio.h>
>
> float foo(float x)
> {
>   float y = 0;
>   while (x > 0.00000001) {
>     y += x*x*x*x*x*x*x*x*x*x*x*x*x;
>     x = x/2;
>   }
>   return y;
> }
>
> int main (int argc, char    *argv[])
> {
>  float y = atoi(argv[1]);
>  printf("%f\n", foo(y));
>  return 0;
> }
>
>
> $ gcc  -ffast-math -O0   t.c
> /tmp/cccA1sUB.o: In function `foo':
> t.c:(.text+0x2c): undefined reference to `powf'
> collect2: error: ld returned 1 exit status
> $ gcc  -ffast-math -O2   t.c
> $ ./a.out 5
> 1220852096.000000
>
>
> FE with -ffast-math replaced x*x*...*x with __builtin_powf. Later with
> -O2 this call is replaced back into multiplications in sincos phase.
> The stability with -O0 is because sincos phase doesn't work on -O0.
>
> I think we must avoid doing this optimization in FE and turn off
> -ffast-math if -O0 is used. Your opinion.

No, I think we should avoid most of the builtin related folding at -O0.

Can you open a bugreport on gcc.gnu.org/bugzilla please?

Thanks,
Richard.

> Thanks,
> Vladimir
>

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

end of thread, other threads:[~2011-08-26 12:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-26 12:52 linking time eroor with -fast-math -O0 Vladimir Yakovlev
2011-08-26 12:55 ` Richard Guenther

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).