[llvm] r199025 - Switch-to-lookup tables: Don't require a result for the default

Rafael EspĂ­ndola rafael.espindola at gmail.com
Mon Jan 20 15:02:43 PST 2014


On 11 January 2014 16:44, Hans Wennborg <hans at hanshq.net> wrote:
> Author: hans
> Date: Sat Jan 11 18:44:41 2014
> New Revision: 199025
>
> URL: http://llvm.org/viewvc/llvm-project?rev=199025&view=rev
> Log:
> Switch-to-lookup tables: Don't require a result for the default
> case when the lookup table doesn't have any holes.
>
> This means we can build a lookup table for switches like this:
>
>   switch (x) {
>     case 0: return 1;
>     case 1: return 2;
>     case 2: return 3;
>     case 3: return 4;
>     default: exit(1);
>   }
>
> The default case doesn't yield a constant result here, but that doesn't matter,
> since a default result is only necessary for filling holes in the lookup table,
> and this table doesn't have any holes.
>
> This makes us transform 505 more switches in a clang bootstrap, and shaves 164 KB
> off the resulting clang binary.

Awesome!

Thanks,
Rafael



More information about the llvm-commits mailing list