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)
commite03d9e4ec7037526b94ce91985e7ff82ebc069fa
tree9ea5f59b7ef92e8909ae6e2aedab077cc1bee2f8
parente803d05bd87d1181c971fb719fef5638dd44ce99
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.

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