[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 17:04:35 PDT 2015


hans added inline comments.

================
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");
----------------
reames wrote:
> majnemer wrote:
> > sanjoy wrote:
> > > majnemer wrote:
> > > > reames wrote:
> > > > > sanjoy wrote:
> > > > > > hans wrote:
> > > > > > > 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
> > > > > > > I don't think checking for >= is sufficient if switches allow duplicate cases, if that's how number of case can be greater than 2^Bits.
> > > > > > 
> > > > > > I had missed your note in the commit message -- given that duplicate values are prohibited, I think it should be sufficient to check for equality.
> > > > > I'll switch to the equality before submission.
> > > > `pow` uses doubles, was this intentional?
> > > > 
> > > > Could we use `1U << Bits` or `1ULL << Bits`?
> > > > Could we use 1U << Bits or 1ULL << Bits?
> > > 
> > > Won't that break if `Bits` is > 64?
> > Right, I guess we'd need to do something like `Log2_32(SI->getNumCases()) >= Bits`.
> I'm tempted to use the shift by Bits with an additional constraint that Bits is <= 63.  I can't imagine we're every going to see a switch with more than 2^63 cases.  :)
We won't; a switch can not have more than 2^32 cases (actually it's probably 2^21-1 or something like that).

But I don't think there's any limit to how wide the switch expression is, so we still need to be careful here.


http://reviews.llvm.org/D11995





More information about the llvm-commits mailing list