This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFH] Folding of (int)round to lround (and friends)
On Tue, 6 Dec 2005, Kaveh R. Ghazi wrote:
> > patch below implements folding of integer conversions of
> > the rounding functions to the specific C99 routines. And there
> > is the problem - given suitable expanders, code generated for
> > lround can be a lot better than for (int)round, but lround is
> > only available from C99 (and maybe doesn't have a library fallback).
> > So with the patch below I get
> >
> > #include <math.h>
> >
> > int foo(double x)
> > {
> > return round(x);
> > }
> >
> > > gcc -c -O2 t.c
> > t.c: In function 'foo':
> > t.c:5: warning: incompatible implicit declaration of built-in function
> > 'llround'
> >
> > which I can only avoid with -std=c99. How do we generally deal with
> > this? Not do the transformation if !c99?
>
> I think you want to check the macro TARGET_C99_FUNCTIONS in your code.
>
> However I thought this transformation, (int)round to lround, was
> already done by GCC. See: gcc.dg/torture/builtin-convert-2.c
>
> Why do we need your patch?
Doh, we indeed do. But it's buried in convert.c:convert_to_integer.
A more appropriate place is fold(). Also with that code we, too,
get the spurious warning, just this time for 'round', not llround:
> gcc -O2 -c t.c
t.c: In function 'foo':
t.c:5: warning: incompatible implicit declaration of built-in function
'round'
I think warning here is a bug.
Richard.