Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
34 changes: 0 additions & 34 deletions llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ static bool processSwitch(SwitchInst *I, LazyValueInfo *LVI,
{ // Scope for SwitchInstProfUpdateWrapper. It must not live during
// ConstantFoldTerminator() as the underlying SwitchInst can be changed.
SwitchInstProfUpdateWrapper SI(*I);
unsigned ReachableCaseCount = 0;

for (auto CI = SI->case_begin(), CE = SI->case_end(); CI != CE;) {
ConstantInt *Case = CI->getCaseValue();
Expand Down Expand Up @@ -408,33 +407,6 @@ static bool processSwitch(SwitchInst *I, LazyValueInfo *LVI,

// Increment the case iterator since we didn't delete it.
++CI;
++ReachableCaseCount;
}

BasicBlock *DefaultDest = SI->getDefaultDest();
if (ReachableCaseCount > 1 &&
!isa<UnreachableInst>(DefaultDest->getFirstNonPHIOrDbg())) {
ConstantRange CR = LVI->getConstantRangeAtUse(I->getOperandUse(0),
/*UndefAllowed*/ false);
// The default dest is unreachable if all cases are covered.
if (!CR.isSizeLargerThan(ReachableCaseCount)) {
BasicBlock *NewUnreachableBB =
BasicBlock::Create(BB->getContext(), "default.unreachable",
BB->getParent(), DefaultDest);
new UnreachableInst(BB->getContext(), NewUnreachableBB);

DefaultDest->removePredecessor(BB);
SI->setDefaultDest(NewUnreachableBB);

if (SuccessorsCount[DefaultDest] == 1)
DTU.applyUpdatesPermissive(
{{DominatorTree::Delete, BB, DefaultDest}});
DTU.applyUpdatesPermissive(
{{DominatorTree::Insert, BB, NewUnreachableBB}});

++NumDeadCases;
Changed = true;
}
}
}

Expand Down Expand Up @@ -1255,12 +1227,6 @@ CorrelatedValuePropagationPass::run(Function &F, FunctionAnalysisManager &AM) {
if (!Changed) {
PA = PreservedAnalyses::all();
} else {
#if defined(EXPENSIVE_CHECKS)
assert(DT->verify(DominatorTree::VerificationLevel::Full));
#else
assert(DT->verify(DominatorTree::VerificationLevel::Fast));
#endif // EXPENSIVE_CHECKS

PA.preserve<DominatorTreeAnalysis>();
PA.preserve<LazyValueAnalysis>();
}
Expand Down
11 changes: 5 additions & 6 deletions llvm/test/Transforms/CorrelatedValuePropagation/basic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ define i32 @switch_range(i32 %cond) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[S:%.*]] = urem i32 [[COND:%.*]], 3
; CHECK-NEXT: [[S1:%.*]] = add nuw nsw i32 [[S]], 1
; CHECK-NEXT: switch i32 [[S1]], label [[DEFAULT_UNREACHABLE:%.*]] [
; CHECK-NEXT: switch i32 [[S1]], label [[UNREACHABLE:%.*]] [
; CHECK-NEXT: i32 1, label [[EXIT1:%.*]]
; CHECK-NEXT: i32 2, label [[EXIT2:%.*]]
; CHECK-NEXT: i32 3, label [[EXIT1]]
Expand All @@ -451,8 +451,6 @@ define i32 @switch_range(i32 %cond) {
; CHECK-NEXT: ret i32 1
; CHECK: exit2:
; CHECK-NEXT: ret i32 2
; CHECK: default.unreachable:
; CHECK-NEXT: unreachable
; CHECK: unreachable:
; CHECK-NEXT: ret i32 0
;
Expand Down Expand Up @@ -515,9 +513,10 @@ define i8 @switch_defaultdest_multipleuse(i8 %t0) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[O:%.*]] = or i8 [[T0:%.*]], 1
; CHECK-NEXT: [[R:%.*]] = srem i8 1, [[O]]
; CHECK-NEXT: br label [[EXIT:%.*]]
; CHECK: default.unreachable:
; CHECK-NEXT: unreachable
; CHECK-NEXT: switch i8 [[R]], label [[EXIT:%.*]] [
; CHECK-NEXT: i8 0, label [[EXIT]]
; CHECK-NEXT: i8 1, label [[EXIT]]
; CHECK-NEXT: ]
; CHECK: exit:
; CHECK-NEXT: ret i8 0
;
Expand Down
301 changes: 0 additions & 301 deletions llvm/test/Transforms/CorrelatedValuePropagation/switch.ll

This file was deleted.