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: PATCH: tweak tree-pretty-print.c


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


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