[PATCH] D35578: Add -fswitch-tables and -fno-switch-tables flags

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 18 14:49:39 PDT 2017

Quuxplusone added a comment.

If the goal is fine-grained control over the heuristics for compiling switch statements, perhaps one should enumerate all the possible ways to lower switch statements --- jump-tables, lookup-tables, if-trees, if-chains, (more?) --- and add a separate flag for each of them.
...Although I'm not sure what purpose there'd really be in saying "This switch statement *must* be compiled into an if-else tree" or "this one *must* be a lookup table"; couldn't that end up being a pessimization one day, as the optimizer gets smarter?

Either way, it sounds like "-fno-switch-tables" is just a synonym for the (soon-to-be-)existing options "-fno-jump-tables -fno-lookup-tables" and therefore doesn't need to exist as a separate option.

Question: Is the intention really specifically about switch heuristics? Or are you trying to prevent the compiler from embedding data into the text section and/or taking computed jumps? Because Clang *can* generate a lookup table in .rodata even if the input code contains no "switch" constructs --- e.g. a long enough chain of "if"s will do the trick. https://godbolt.org/g/ZQqkaB


More information about the cfe-commits mailing list