Do simple constant propagation in lookup table formation for switches
authorHans Wennborg <hans@hanshq.net>
Wed, 31 Oct 2012 13:42:45 +0000 (13:42 +0000)
committerHans Wennborg <hans@hanshq.net>
Wed, 31 Oct 2012 13:42:45 +0000 (13:42 +0000)
commit9e74dd97b8092174214ce0885dca5b56c5b9eba7
treee5787617b357676ae259c65968f7f7eadec794e4
parent86bdab74688b6e3bfac37c62b7ef0644e8616b11
Do simple constant propagation in lookup table formation for switches

By propagating the value for the switch condition, LLVM can now build
lookup tables for code such as:

  switch (x) {
    case 1: return 5;
    case 2: return 42;
    case 3: case 4: case 5:
      return x - 123;
    default:
      return 123;
  }

Given that x is known for each case, "x - 123" becomes a constant for
cases 3, 4, and 5.

llvm-svn: 167115
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/switch_to_lookup_table.ll