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

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 1 07:57:30 PDT 2015


hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm


================
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");
----------------
reames wrote:
> 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.  
Even if the next round will take care of it, it seems simple enough that we might as well handle it while we're here the first time.

It's no big deal though, and if you prefer to not do it that's fine too; as long as the example works, I'm happy.


http://reviews.llvm.org/D12497





More information about the llvm-commits mailing list