Skip to content

Commit 36e372d

Browse files
committed
[IR][NFC] Use SwitchInst::defaultDestUndefined
1 parent d7afafd commit 36e372d

File tree

4 files changed

+8
-16
lines changed

4 files changed

+8
-16
lines changed

llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,8 @@ static bool processSwitch(SwitchInst *I, LazyValueInfo *LVI,
410410
++ReachableCaseCount;
411411
}
412412

413-
BasicBlock *DefaultDest = SI->getDefaultDest();
414-
if (ReachableCaseCount > 1 &&
415-
!isa<UnreachableInst>(DefaultDest->getFirstNonPHIOrDbg())) {
413+
if (ReachableCaseCount > 1 && !SI->defaultDestUndefined()) {
414+
BasicBlock *DefaultDest = SI->getDefaultDest();
416415
ConstantRange CR = LVI->getConstantRangeAtUse(I->getOperandUse(0),
417416
/*UndefAllowed*/ false);
418417
// The default dest is unreachable if all cases are covered.

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,8 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions,
203203
BasicBlock *TheOnlyDest = DefaultDest;
204204

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

211209
bool Changed = false;
212210

llvm/lib/Transforms/Utils/LowerSwitch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ void ProcessSwitchInst(SwitchInst *SI,
388388
ConstantInt *UpperBound = nullptr;
389389
bool DefaultIsUnreachableFromSwitch = false;
390390

391-
if (isa<UnreachableInst>(Default->getFirstNonPHIOrDbg())) {
391+
if (SI->defaultDestUndefined()) {
392392
// Make the bounds tightly fitted around the case value range, because we
393393
// know that the value passed to the switch must be exactly one of the case
394394
// values.

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)