optimization of switch statements on i386
Ian Lance Taylor
iant@google.com
Mon Feb 11 19:31:00 GMT 2008
"Godmar Back" <godmar@gmail.com> writes:
> Thanks. I did see that gcc_unreachable() showed up as a symbol in the
> assembly (consistent with it not meaning anything special); I suppose
> I was misled by this comment in the gcc coding conventions at
> http://gcc.gnu.org/codingconventions.html
>
> "Use gcc_unreachable() to mark places that should never be reachable
> (such as an unreachable default case of a switch). Do not use
> gcc_assert(0) for such purposes, as gcc_unreachable gives the compiler
> more information."
>
> Apparently, this discussion refers to the (currently executing)
> compiler, not the compiler used to compile the gcc code.
Those coding convention are for people working on gcc itself, not for
people using gcc.
> I assume a corollary of that statement is that there is no way to
> trick the compiler into omitting the default branch without incurring
> runtime checks (or is there a clever way I'm not realizing)?
In general, yes.
There has been some discussion of implementing __builtin_unreachable()
which would direct the optimizers to assume that the code path was
never taken. Howver, as far as I know no actual woek has been done on
this.
Ian
More information about the Gcc-help
mailing list