Remove the final bit test during lowering switch statement if all cases in bit test...
authorCong Hou <congh@google.com>
Tue, 25 Aug 2015 21:34:38 +0000 (21:34 +0000)
committerCong Hou <congh@google.com>
Tue, 25 Aug 2015 21:34:38 +0000 (21:34 +0000)
commit4193a13da473bd0f1087ab58097e23d6ce60a3ee
treee6937c46f424e1d698f59dd81288ac50a6998c9f
parent3104975f8a902e5dd3e82927403d0e54f3688615
Remove the final bit test during lowering switch statement if all cases in bit test cover a contiguous range.

When lowering switch statement, if bit tests are used then LLVM will always generates a jump to the default statement in the last bit test. However, this is not necessary when all cases in bit tests cover a contiguous range. This is because when generating the bit tests header MBB, there is a range check that guarantees cases in bit tests won't go outside of [low, high], where low and high are minimum and maximum case values in the bit tests. This patch checks if this is the case and then doesn't emit jump to default statement and hence saves a bit test and a branch.

Differential Revision: http://reviews.llvm.org/D12249

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245976 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
test/CodeGen/X86/switch.ll