Allow switch-to-lookup table for tables with holes by adding bitmask check
authorHans Wennborg <hans@hanshq.net>
Wed, 12 Mar 2014 18:35:40 +0000 (18:35 +0000)
committerHans Wennborg <hans@hanshq.net>
Wed, 12 Mar 2014 18:35:40 +0000 (18:35 +0000)
commit09a31f31545b7360c78265f9ca9cd35430ea401d
treea4ffbf24e8eb4b02594803060b38c148dc859684
parent365f0455a6b202d349619ad9be3f2bccabc76d92
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!

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