Allow switch-to-lookup table for tables with holes by adding bitmask check

Press ? to show keyboard shortcuts.
Committed
hansMar 12 2014, 11:35 AM
Parents
rL203693: Objective-C. Issue diagnostics on mismatched methods when their selector is used
Branches
Unknown
Tags
Unknown
Description

Allow switch-to-lookup table for tables with holes by adding bitmask check

This allows us to generate table lookups for code such as:

unsigned test(unsigned x) {
  switch (x) {
    case 100: return 0;
    case 101: return 1;
    case 103: return 2;
    case 105: return 3;
    case 107: return 4;
    case 109: return 5;
    case 110: return 6;
    default: return f(x);
  }
}

Since cases 102, 104, etc. are not constants, the lookup table has holes
in those positions. We therefore guard the table lookup with a bitmask check.

Patch by Jasper Neumann!

rL203694

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

Loading...

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

Loading...

Add Comment