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

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 31 17:34:35 PDT 2015


reames added inline comments.

================
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");
----------------
hans wrote:
> 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
> }
> ```
This example will work today, just as two rounds.  We'll first delete the dead case, then come back around (within the same run of the pass) and delete the dead default.  Your requested change would basically just change the order of the two steps.  We could try to do everything at once, but doing each step individually seems less error prone.  


http://reviews.llvm.org/D12497





More information about the llvm-commits mailing list