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 Nov 7, 2003, at 1:00 AM, Richard Guenther wrote:


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);
}
...
double mysqrt(double x)
{
  if (!(x >= 0.0))
    abort();
  return sqrt(x);
}
... should be transformed into ....
  if (!(x >= 0)) {
     ??
  } else {
    return sqrt(x);
  }

Unfortunately, assert(exp) is guaranteed not to evaluate "exp" when NDEBUG is set.


In this case, evaluating "x >= 0.0" may result in a change to the FP exception state.

This transformation is interesting only in the case where the expression has no side-effects.

+------------------------------------------------------------+
| Alexander M. Rosenberg           <mailto:alexr@_spies.com> |
| Nobody cares what I say. Remove the underscore to mail me. |


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