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


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.


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