Two case switch to select optimization
authorMarcello Maggioni <hayarms@gmail.com>
Tue, 7 Oct 2014 18:16:44 +0000 (18:16 +0000)
committerMarcello Maggioni <hayarms@gmail.com>
Tue, 7 Oct 2014 18:16:44 +0000 (18:16 +0000)
commit5c98f14b787e476636196939eb4dbfcce8615906
treedac9a5eec3f9a5ddd2ff2eb898c0ecefffb5b2df
parentebc756d0d7c74a9399243d0c4c50ff6a5c9cb687
Two case switch to select optimization

This optimization tries to convert switch instructions that are used to select a value with only 2 unique cases + default block
to a select or a couple of selects (depending if the default block is reachable or not).

The typical case this optimization wants to be able to optimize is this one:

Example:
switch (a) {
  case 10:                %0 = icmp eq i32 %a, 10
    return 10;            %1 = select i1 %0, i32 10, i32 4
  case 20:        ---->   %2 = icmp eq i32 %a, 20
    return 2;             %3 = select i1 %2, i32 2, i32 %1
  default:
    return 4;
}

It also sets the base for further optimizations that are planned and being reviewed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219223 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Utils/SimplifyCFG.cpp
test/Transforms/SimplifyCFG/UnreachableEliminate.ll
test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll
test/Transforms/SimplifyCFG/switch-to-select-two-case.ll [new file with mode: 0644]