[RFC/PATCH] Optimize code based on asserts even in NDEBUG mode

Richard Guenther rguenth@tat.physik.uni-tuebingen.de
Sat Apr 10 12:25:00 GMT 2004


Paolo Bonzini wrote:
>>To followup myself.  I'd rather do this at tree-ssa level, disallowing
>>side-effects in the __builtin_false() arguments (as this would not only
>>compilcate implementation, but also is asking for trouble).
> 
> 
> My intended approach in tree-ssa would be to expand
> 
> __builtin_assert (x)
> 
> to
> 
> if (__builtin_false () && !x)
>   abort ();
> 
> Now the tree optimizers would know nil about __builtin_false () and assume x
> in the rest of the code; at expansion time __builtin_false () would be 0 (like
> when expanding __builtin_constant_p) and the RTL dead code elimination would
> kill the if and more importantly the evaluation of x.

But I suspect having this "special" CFG (how do you call such edges with 
noreturn attribute?) will confuse further high-level tree optimizers, 
such as the loop optimizer?  I.e. is the loop-optimizer happy with

for (int i=i0; i<i1; ++i) {
   if (__builtin_false() && !(i >= mini && i <= maxi))
     abort();
   ...
}

?

Or does it rather like the if() removed before loop optimization?

Richard.



More information about the Gcc-patches mailing list