[SimplifyCFG] try harder to forward switch condition to phi (PR34471)
authorSanjay Patel <spatel@rotateright.com>
Sun, 22 Oct 2017 16:51:03 +0000 (16:51 +0000)
committerSanjay Patel <spatel@rotateright.com>
Sun, 22 Oct 2017 16:51:03 +0000 (16:51 +0000)
commit24226504a7d18cb626e41f27c8154c95aa2bf08a
tree4e5ac85153f6eedef4f33c50b7eab21bf08d240e
parent81b756e6a3e491d43ac18ed39a9ffb13f45b9ea4
[SimplifyCFG] try harder to forward switch condition to phi (PR34471)

The missed canonicalization/optimization in the motivating test from PR34471 leads to very different codegen:

  int switcher(int x) {
      switch(x) {
      case 17: return 17;
      case 19: return 19;
      case 42: return 42;
      default: break;
      }
      return 0;
    }

  int comparator(int x) {
    if (x == 17) return 17;
    if (x == 19) return 19;
    if (x == 42) return 42;
    return 0;
  }

For the first example, we use a bit-test optimization to avoid a series of compare-and-branch:
https://godbolt.org/g/BivDsw

Differential Revision: https://reviews.llvm.org/D39011

llvm-svn: 316293
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/ForwardSwitchConditionToPHI.ll