[llvm-commits] [Patch] Switch-to-lookup tables: do simple constant propagation

Hans Wennborg hans at chromium.org
Thu Oct 4 06:45:25 PDT 2012


On Wed, Oct 3, 2012 at 8:37 PM, Sean Silva <silvas at purdue.edu> wrote:
>> If a lookup table isn't formed, it may also be useful to merge blocks to
>> create a subtract(or some similar calculation) even it wasn't written in the
>> code? So maybe we could splits the blocks and then recombine them if lookup
>
> This is kind of the "tip of the iceberg" for a lot of different kinds
> of simplifications. Once we start replacing cases with a "closed form"
> such as subtraction, that opens the door to more generally replace
> manually specified case->val mappings with a closed form.

Yeah, I think merging blocks back once they've been split up seems hard.

It seems to me that there are two alternatives here:

1. Clone the blocks that generate constants in general. The upside is
that each block becomes very simple (just a branch). The downside is
that the number of blocks increases, which could mean larger code
size, and if the switch doesn't get lowered to a jump table, it also
means additional instructions to jump to each case. I guess the
problem here is deciding when this general switch simplification is
actually a simplification.

2. Only clone the blocks when the switch will be replaced by a lookup
table. This is always a win (unless the constants are larger than the
block addresses), because we build lookup tables for switches that
would otherwise get jump tables, and thus just replace one table with
another. If we go with this one, we might as well do it during lookup
table construction.

Thanks,
Hans



More information about the llvm-commits mailing list