@@ -5715,8 +5715,7 @@ bool SimplifyCFGOpt::turnSwitchRangeIntoICmp(SwitchInst *SI,
57155715 IRBuilder<> &Builder) {
57165716 assert (SI->getNumCases () > 1 && " Degenerate switch?" );
57175717
5718- bool HasDefault =
5719- !isa<UnreachableInst>(SI->getDefaultDest ()->getFirstNonPHIOrDbg ());
5718+ bool HasDefault = !SI->defaultDestUndefined ();
57205719
57215720 auto *BB = SI->getParent ();
57225721
@@ -5879,8 +5878,7 @@ static bool eliminateDeadSwitchCases(SwitchInst *SI, DomTreeUpdater *DTU,
58795878 // default destination becomes dead and we can remove it. If we know some
58805879 // of the bits in the value, we can use that to more precisely compute the
58815880 // number of possible unique case values.
5882- bool HasDefault =
5883- !isa<UnreachableInst>(SI->getDefaultDest ()->getFirstNonPHIOrDbg ());
5881+ bool HasDefault = !SI->defaultDestUndefined ();
58845882 const unsigned NumUnknownBits =
58855883 Known.getBitWidth () - (Known.Zero | Known.One ).popcount ();
58865884 assert (NumUnknownBits <= Known.getBitWidth ());
@@ -6237,11 +6235,8 @@ static bool initializeUniqueCases(SwitchInst *SI, PHINode *&PHI,
62376235 // is unreachable.
62386236 DefaultResult =
62396237 DefaultResults.size () == 1 ? DefaultResults.begin ()->second : nullptr ;
6240- if ((!DefaultResult &&
6241- !isa<UnreachableInst>(DefaultDest->getFirstNonPHIOrDbg ())))
6242- return false ;
62436238
6244- return true ;
6239+ return DefaultResult || SI-> defaultDestUndefined () ;
62456240}
62466241
62476242// Helper function that checks if it is possible to transform a switch with only
@@ -7281,7 +7276,7 @@ static bool simplifySwitchOfPowersOfTwo(SwitchInst *SI, IRBuilder<> &Builder,
72817276 // We perform this optimization only for switches with
72827277 // unreachable default case.
72837278 // This assumtion will save us from checking if `Condition` is a power of two.
7284- if (!isa<UnreachableInst>( SI->getDefaultDest ()-> getFirstNonPHIOrDbg () ))
7279+ if (!SI->defaultDestUndefined ( ))
72857280 return false ;
72867281
72877282 // Check that switch cases are powers of two.
0 commit comments