Build lookup tables for switches (PR884)
authorHans Wennborg <hans@hanshq.net>
Thu, 6 Sep 2012 09:43:28 +0000 (09:43 +0000)
committerHans Wennborg <hans@hanshq.net>
Thu, 6 Sep 2012 09:43:28 +0000 (09:43 +0000)
commit486270aee6ffd2a0c3c2333a8a0091c29f037aae
tree61d8a3cde0a2906aa8492b476de25f2ee88a00a9
parentc05d30601ced172b55be81bb529df6be91d6ae15
Build lookup tables for switches (PR884)

This adds a transformation to SimplifyCFG that attemps to turn switch
instructions into loads from lookup tables. It works on switches that
are only used to initialize one or more phi nodes in a common successor
basic block, for example:

  int f(int x) {
    switch (x) {
    case 0: return 5;
    case 1: return 4;
    case 2: return -2;
    case 5: return 7;
    case 6: return 9;
    default: return 42;
  }

This speeds up the code by removing the hard-to-predict jump, and
reduces code size by removing the code for the jump targets.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163302 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Utils/SimplifyCFG.cpp
test/Transforms/SimplifyCFG/switch_create.ll
test/Transforms/SimplifyCFG/switch_to_lookup_table.ll [new file with mode: 0644]