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

Chris Lattner clattner at apple.com
Mon Jan 20 21:57:13 PST 2014


On Jan 11, 2014, at 4:44 PM, 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.

This is great work Hans!!

-Chris



More information about the llvm-commits mailing list