Switch-to-lookup tables: Don't require a result for the default
authorHans Wennborg <hans@hanshq.net>
Sun, 12 Jan 2014 00:44:41 +0000 (00:44 +0000)
committerHans Wennborg <hans@hanshq.net>
Sun, 12 Jan 2014 00:44:41 +0000 (00:44 +0000)
commit19236d53eb6f4ee4538ac12efcd77000b2f7ae78
treed8012f87d9e6d7d3d00f1efa5a98ded6d09f66a4
parent50e6d23f0d50d69b14eecd6a38a375cc07101a07
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199025 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Utils/SimplifyCFG.cpp
test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll