This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/32074] Optimizer does not exploit assertions
- From: "siarhei.siamashka at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 29 Mar 2012 10:11:39 +0000
- Subject: [Bug middle-end/32074] Optimizer does not exploit assertions
- Auto-submitted: auto-generated
- References: <bug-32074-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32074
--- Comment #8 from Siarhei Siamashka <siarhei.siamashka at gmail dot com> 2012-03-29 10:11:39 UTC ---
(In reply to comment #5)
> (In reply to comment #4)
> > We have __builtin_unreachable() now which should allow for this optimization.
>
> I've been using __builtin_unreachable() for some time now, and it's very nice
> for its intended purpose (telling gcc when it's safe to produce better code).
> I've noticed, though, that the ``x'' passed to assert(x) in already-existing
> code is often too expensive (or side effect-ful) to optimize away when
> converted to ``if(!(x)) { __builtin_unreachable(); }''
Based on your comment, looks like asserts are just a superset of
__builtin_unreachable() because asserts give more freedom to the compiler to
either evaluate the expression or optimize it out. It's easy to replace
__builtin_unreachable() with assert(0), but not the other way around as you
have clearly demonstrated. Hence this enhancement request does not look to be
fully resolved yet.