Switch lowering: exploit unreachable fall-through when lowering case range cluster
authorHans Wennborg <hans@hanshq.net>
Fri, 29 Mar 2019 13:40:05 +0000 (13:40 +0000)
committerHans Wennborg <hans@hanshq.net>
Fri, 29 Mar 2019 13:40:05 +0000 (13:40 +0000)
commit800b12f90a43d83d17a0e31ad09983033b6789af
tree0af705e2125d2cc960a704f2c0a73cc72fb3825c
parent881bcbe09471c9e6ae70228cf9754d568ac8e350
Switch lowering: exploit unreachable fall-through when lowering case range cluster

In the example below, we would previously emit two range checks, one for cases
1--3 and one for 4--6. This patch makes us exploit the fact that the
fall-through is unreachable and only one range check is necessary.

  switch i32 %i, label %default [
    i32 1,  label %bb1
    i32 2,  label %bb1
    i32 3,  label %bb1
    i32 4,  label %bb2
    i32 5,  label %bb2
    i32 6,  label %bb2
  ]
  default: unreachable

llvm-svn: 357252
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
llvm/test/CodeGen/AArch64/switch-unreachable-default.ll
llvm/test/CodeGen/X86/switch.ll