[PATCH] D12497: [SimplifyCFG] Use known bits to eliminate dead switch defaults

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 31 13:36:28 PDT 2015


hans added a comment.

Thanks for the patch!


================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:3262
@@ -3257,1 +3261,3 @@
+      NumUnknownBits < 64 /* avoid overflow */ &&  
+      SI->getNumCases() == (1ULL << NumUnknownBits)) {
     DEBUG(dbgs() << "SimplifyCFG: switch default is dead.\n");
----------------
Instead of making this contingent on DeadCases.empty(), can't we use "SI->getNumCases() - DeadCases.size()" to get the number of live cases?

The situation I have in mind:

```
x &= 0x3; // NumUnknownBits is now 2
switch (x) {
case 0, 1, 2, 3: stuff
case 5: dead
default: dead
}
```


http://reviews.llvm.org/D12497





More information about the llvm-commits mailing list