public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@google.com>
To: "Godmar Back" <godmar@gmail.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: optimization of switch statements on i386
Date: Mon, 11 Feb 2008 19:31:00 -0000	[thread overview]
Message-ID: <m3ejbjs336.fsf@localhost.localdomain> (raw)
In-Reply-To: <719dced30802111013j661b2e25u45e5c775f6a8a2ec@mail.gmail.com>

"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

  reply	other threads:[~2008-02-11 19:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <719dced30802081629g19f67f6fi76dfaa0ede35b7aa@mail.gmail.com>
2008-02-09  0:31 ` Godmar Back
2008-02-09  2:05   ` Ian Lance Taylor
2008-02-09  2:43     ` Godmar Back
2008-02-09  2:52       ` Ian Lance Taylor
2008-02-09  3:02     ` Godmar Back
2008-02-11 17:55       ` Ian Lance Taylor
2008-02-11 18:13         ` Godmar Back
2008-02-11 19:31           ` Ian Lance Taylor [this message]
2008-02-11 18:47         ` Diego Novillo
2008-02-11 19:52           ` Godmar Back
2008-02-11 20:01             ` Ian Lance Taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3ejbjs336.fsf@localhost.localdomain \
    --to=iant@google.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=godmar@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).