Home

Switch-to-lookup tables: Don't require a result for the default

Press ? to show keyboard shortcuts.
Committed
hansJan 11 2014, 4:44 PM
Parents
rL199024: [Sparc] Add missing processor types: v7 and niagara
Branches
Unknown
Tags
Unknown
Subscribers
None
Projects
None
Description

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.

rL199025

llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp

Loading...

llvm/trunk/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll

Loading...

Add Comment