This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Use assert()s for optimization?
- From: Richard Guenther <rguenth at tat dot physik dot uni-tuebingen dot de>
- To: Falk Hueffner <falk dot hueffner at student dot uni-tuebingen dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 7 Nov 2003 10:00:12 +0100 (CET)
- Subject: Re: Use assert()s for optimization?
On Thu, 6 Nov 2003, Richard Guenther wrote:
> On Thu, 6 Nov 2003, Falk Hueffner wrote:
>
> > Richard Guenther <rguenth@tat.physik.uni-tuebingen.de> writes:
> >
> > > Is there a way to turn an assert() into optimization hints for gcc?
> > > Like in
> > >
> > > double mysqrt(double x)
> > > {
> > > assert(x >= 0.0);
> > > return sqrt(x);
> > > }
Maybe I should tell something more I was looking for. The above, in debug
compilation expands to something like
double mysqrt(double x)
{
if (!(x >= 0.0))
abort();
return sqrt(x);
}
and with clever if-conversion and cprop the compiler will optimize the
call to sqrt() as if in -ffast-math. But as soon as I swith to optimized
compiling we get
double mysqrt(double x)
{
return sqrt(x);
}
which doesnt allow the compiler to optimize anymore.
So the question is, is there a expansion for assert() that looks like the
debuggin one, but tells the compiler the condition is actually never met?
So if-conversion can still take place generating
if (!(x >= 0)) {
??
} else {
return sqrt(x);
}
but the expansion in ?? will cause the compiler to throw away the if arm
of the cond expression?
Thanks again,
Richard.
--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/