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: Richard Guenther <rguenth at tat dot physik dot uni-tuebingen dot de>, gcc at gcc dot gnu dot org
- Date: Thu, 6 Nov 2003 23:15:47 +0100 (CET)
- Subject: Re: Use assert()s for optimization?
- References: <Pine.LNX.4.58.0311062248040.599@goofy> <874qxhdumh.fsf@student.uni-tuebingen.de>
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);
> > }
>
> Interestingly, Toon Moene just asked for the same thing on gcc-patches :)
> I don't think it's currently possible. Maybe we could have
> something similar to Microsoft's __assume(), which would then feed the
> nonnegative_p etc. functions and the VRP to come. I'm not sure how to
> represent it best in the intermediary representation, though.
It should probably turn right into REG_EQUAL notes and the like by
cse/gcse. So like we do with the redundant null pointer check for
if (!foo)
abort();
if (foo)
bar();
should work for __assume(), too - just not creating code for the first
test (or possibly do with a special flag). So its __builtin_assert() with
the compiler taking advantage out of it in optimized builds.
Richard.