Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,8 @@ static bool processSwitch(SwitchInst *I, LazyValueInfo *LVI,
++ReachableCaseCount;
}

BasicBlock *DefaultDest = SI->getDefaultDest();
if (ReachableCaseCount > 1 &&
!isa<UnreachableInst>(DefaultDest->getFirstNonPHIOrDbg())) {
if (ReachableCaseCount > 1 && !SI->defaultDestUndefined()) {
BasicBlock *DefaultDest = SI->getDefaultDest();
ConstantRange CR = LVI->getConstantRangeAtUse(I->getOperandUse(0),
/*UndefAllowed*/ false);
// The default dest is unreachable if all cases are covered.
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/Transforms/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions,
BasicBlock *TheOnlyDest = DefaultDest;

// If the default is unreachable, ignore it when searching for TheOnlyDest.
if (isa<UnreachableInst>(DefaultDest->getFirstNonPHIOrDbg()) &&
SI->getNumCases() > 0) {
if (SI->defaultDestUndefined() && SI->getNumCases() > 0)
TheOnlyDest = SI->case_begin()->getCaseSuccessor();
}

bool Changed = false;

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/LowerSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void ProcessSwitchInst(SwitchInst *SI,
ConstantInt *UpperBound = nullptr;
bool DefaultIsUnreachableFromSwitch = false;

if (isa<UnreachableInst>(Default->getFirstNonPHIOrDbg())) {
if (SI->defaultDestUndefined()) {
// Make the bounds tightly fitted around the case value range, because we
// know that the value passed to the switch must be exactly one of the case
// values.
Expand Down
13 changes: 4 additions & 9 deletions llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5715,8 +5715,7 @@ bool SimplifyCFGOpt::turnSwitchRangeIntoICmp(SwitchInst *SI,
IRBuilder<> &Builder) {
assert(SI->getNumCases() > 1 && "Degenerate switch?");

bool HasDefault =
!isa<UnreachableInst>(SI->getDefaultDest()->getFirstNonPHIOrDbg());
bool HasDefault = !SI->defaultDestUndefined();

auto *BB = SI->getParent();

Expand Down Expand Up @@ -5879,8 +5878,7 @@ static bool eliminateDeadSwitchCases(SwitchInst *SI, DomTreeUpdater *DTU,
// default destination becomes dead and we can remove it. If we know some
// of the bits in the value, we can use that to more precisely compute the
// number of possible unique case values.
bool HasDefault =
!isa<UnreachableInst>(SI->getDefaultDest()->getFirstNonPHIOrDbg());
bool HasDefault = !SI->defaultDestUndefined();
const unsigned NumUnknownBits =
Known.getBitWidth() - (Known.Zero | Known.One).popcount();
assert(NumUnknownBits <= Known.getBitWidth());
Expand Down Expand Up @@ -6237,11 +6235,8 @@ static bool initializeUniqueCases(SwitchInst *SI, PHINode *&PHI,
// is unreachable.
DefaultResult =
DefaultResults.size() == 1 ? DefaultResults.begin()->second : nullptr;
if ((!DefaultResult &&
!isa<UnreachableInst>(DefaultDest->getFirstNonPHIOrDbg())))
return false;

return true;
return DefaultResult || SI->defaultDestUndefined();
}

// Helper function that checks if it is possible to transform a switch with only
Expand Down Expand Up @@ -7281,7 +7276,7 @@ static bool simplifySwitchOfPowersOfTwo(SwitchInst *SI, IRBuilder<> &Builder,
// We perform this optimization only for switches with
// unreachable default case.
// This assumtion will save us from checking if `Condition` is a power of two.
if (!isa<UnreachableInst>(SI->getDefaultDest()->getFirstNonPHIOrDbg()))
if (!SI->defaultDestUndefined())
return false;

// Check that switch cases are powers of two.
Expand Down
Loading