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

Hans Wennborg hans at chromium.org
Mon Oct 29 10:54:34 PDT 2012


On Wed, Oct 10, 2012 at 9:55 AM, Hans Wennborg <hans at chromium.org> wrote:
> 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?

Ping? Attaching a rebased patch for convenience.

Thanks,
Hans
-------------- next part --------------
A non-text attachment was scrubbed...
Name: switch_table_const_prop2.patch
Type: application/octet-stream
Size: 12299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121029/2cfaee15/attachment.obj>


More information about the llvm-commits mailing list