http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54505

Steven Bosscher <steven at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |steven at gcc dot gnu.org
         Resolution|                            |WORKSFORME

--- Comment #5 from Steven Bosscher <steven at gcc dot gnu.org> 2012-09-09 
21:27:30 UTC ---

> gcc should make the transformation when it improves the code (like
> all other transformations).

And how is gcc supposed to tell when this is an improvement? Your "like all
other transformations" makes no sense, this is not something simple like
constant propagation or redundancy elimination that's almost always a win.

> gcc often transforms a switch to a dispatch table,

Yes, an existing switch, that someone wrote or generated deliberately as a
switch.


> gcc should allow the programmer to write the code in the cleanest way,
> and transform it to the most performing way.

Kicking in open doors doesn't help.


A compiler is not an omniscient, omnipotent translator. If the compiler can't
tell whether the transformation is profitable, it has to use some heuristics to
make a best guess.

In this case, the trade-off is expanding a compact indirect call to a large
body of a switch statement. This might increase the number of branches (e.g. if
the switch is lowered as a decision tree), it could ruin icache, and it may go
against the intent of the programmer. There are no immediately obvious benefits
visible to the compiler.

With -fprofile-use GCC already performs inlining of the most frequently called
callee of an indirect function calls table. It's the only situation where GCC
can be sure that the transformation is profitable.

If you want a switch, write a switch.

Reply via email to