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

Hans Wennborg hans at chromium.org
Wed Oct 10 01:55:28 PDT 2012


On Wed, Oct 3, 2012 at 1:51 PM, Duncan Sands <baldrick at free.fr> wrote:
>
>> A patch [1] by Craig earlier this week pointed out that Clang fails to
>> build lookup tables for switches like this:
>>
>>    switch(x) {
>>      case 1: return 5;
>>      case 2: return 42;
>>      case 3: case 4: case 5:
>>        return x - 123;
>>      default: return 123;
>>    }
>>
>> Where the resulting value for the 3, 4, 5 cases is "x - 123", rather
>> than a constant.
>
>
> maybe it is better to do this as part of some more generic switch
> simplification
> logic rather than during table construction.

We chatted about this on IRC last week, and I think we concluded that
it seemed hard to determine when it would be profitable to do this
transformation in general, and that it probably made sense to just do
it when forming lookup tables.

If so, I'd like to move forward with this patch.

Does anyone have comments on the constant propagation code itself?
Does it look sensible, or are there any utility functions I could
reuse?

Thanks,
Hans



More information about the llvm-commits mailing list