This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]