[PATCH] D11995: [SimplifyCFG] Prune code from a provably unreachable switch default

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 15:34:14 PDT 2015


hans added a comment.

Nice!


================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:3255
@@ +3254,3 @@
+    !isa<UnreachableInst>(SI->getDefaultDest()->getFirstNonPHIOrDbg());
+  if (HasDefault && DeadCases.empty() && 
+      SI->getNumCases() >= pow(2,Bits)) {
----------------
hmm, why does DeadCases have to be empty?

================
Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:3256
@@ +3255,3 @@
+  if (HasDefault && DeadCases.empty() && 
+      SI->getNumCases() >= pow(2,Bits)) {
+    DEBUG(dbgs() << "SimplifyCFG: switch default is dead.\n");
----------------
sanjoy wrote:
> Can `SI->getNumCases()` ever be `> pow(2, Bits)`?
> 
> I don't think checking for `>=` is sufficient if `switch`es allow duplicate cases, if that's how number of case can be greater than 2^Bits.
ultra nit: space between , and Bits


http://reviews.llvm.org/D11995





More information about the llvm-commits mailing list