[SimplifyCFG] Use known bits to eliminate dead switch defaults
authorPhilip Reames <listmail@philipreames.com>
Thu, 10 Sep 2015 17:44:47 +0000 (17:44 +0000)
committerPhilip Reames <listmail@philipreames.com>
Thu, 10 Sep 2015 17:44:47 +0000 (17:44 +0000)
commit053701399d42c76fdaff6c16f44494516c046c80
treee2447d469701ea9932899126ef036706e3662512
parenta5478698bf4d7ed356621a29576e7259c082b25c
[SimplifyCFG] Use known bits to eliminate dead switch defaults

This is a follow up to http://reviews.llvm.org/D11995 implementing the suggestion by Hans.

If we know some of the bits of the value being switched on, we know that the maximum number of unique cases covers the unknown bits. This allows to eliminate switch defaults for large integers (i32) when most bits in the value are known.

Note that I had to make the transform contingent on not having any dead cases. This is conservatively correct with the old code, but required for the new code since we might have a dead case which varies one of the known bits. Counting that towards our number of covering cases would be bad.  If we do have dead cases, we'll eliminate them first, then revisit the possibly dead default.

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

llvm-svn: 247309
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/switch-dead-default.ll