This is the mail archive of the gcc-patches@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: [RFC/PATCH] Optimize code based on asserts even in NDEBUG mode


> > int f(char *x) {
> >    if (__builtin_this_is_false(!(x != NULL)))
> >      abort();
> >    return x ? *x : 0;
> > }
> >
> > this may have other uses than a (broken) assert optimization.
> >
> > Of course, if in this case x _is_ actually NULL, we create
> > wrong code,
> > but we were asked for this.
>
>   Isn't this what __builtin_expect is for?  Can't anyone who wan't this
> functionality just define their own variant assert macro that combines
> assert with expect?

No. __builtin_expect says what the most likely value is. It does not indicate 
that other values are impossible.

In the case above we would not be able to eliminate the null check, just 
structure the code such that the fast path is taken when x != NULL.

Paul


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