This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH: tweak tree-pretty-print.c
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: Ben Elliston <bje at au1 dot ibm dot com>, <gcc-patches at gcc dot gnu dot org>
- Date: 09 May 2006 17:39:04 +0200
- Subject: Re: PATCH: tweak tree-pretty-print.c
- References: <Pine.LNX.4.44.0605090822470.9011-100000@www.eyesopen.com>
Roger Sayle <roger@eyesopen.com> writes:
[...]
| More generally,
|
| if (x == 1)
| foo ();
| else if (x == 2)
| bar ();
| else switch (x)
| ...
|
| is conceptually equivalent to
|
| switch (x)
| {
| case 1:
| foo();
| break;
|
| case 2:
| bar();
| break;
|
| ...
| }
when it makes the code clearer yes, I wholeheartly agree it is the way to
write for human consumption. However, it is the sort of
transformation the compiler should seek for -- when it is provably
possible with minimal or small cost (e.g. I don't require the compiler
to be super-smart).
| Indeed, depending upon the distribution of "x", as provided by profiling
| for example, a compiler could transform the second form into the first,
| or the first form into the second. In this particular case, we know
| a priori, that most strings are longer than one or two characters, so
| NUL's are relatively rare/infrequent, making the second form preferrable.
|
| I beleive Edmar Wienskoski will be giving a presentation on this
| form of feedback directed switch optimization, at this year's GCC
| summit:
| http://www.gccsummit.org/2006/view_abstract.php?content_key=18
I don't know yet whether I would make it -- I hope to be there
but nothing for sure yet.
Thanks,
-- Gaby