llvm.org GIT mirror llvm / 273aba7
CorrelatedValuePropagation: Preserve DT. Summary: We only modify CFG in a couple of places, and we can preserve DT there with a little effort. Reviewers: davide, vsk Subscribers: hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D48059 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@334895 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Zolotukhin 1 year, 3 months ago
4 changed file(s) with 18 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
8181 AU.addRequired();
8282 AU.addRequired();
8383 AU.addPreserved();
84 AU.addPreserved();
8485 }
8586 };
8687
305306 /// that cannot fire no matter what the incoming edge can safely be removed. If
306307 /// a case fires on every incoming edge then the entire switch can be removed
307308 /// and replaced with a branch to the case destination.
308 static bool processSwitch(SwitchInst *SI, LazyValueInfo *LVI) {
309 static bool processSwitch(SwitchInst *SI, LazyValueInfo *LVI, DominatorTree *DT) {
309310 Value *Cond = SI->getCondition();
310311 BasicBlock *BB = SI->getParent();
311312
320321
321322 // Analyse each switch case in turn.
322323 bool Changed = false;
324 DenseMap SuccessorsCount;
325 for (auto *Succ : successors(BB))
326 SuccessorsCount[Succ]++;
327
323328 for (auto CI = SI->case_begin(), CE = SI->case_end(); CI != CE;) {
324329 ConstantInt *Case = CI->getCaseValue();
325330
354359
355360 if (State == LazyValueInfo::False) {
356361 // This case never fires - remove it.
357 CI->getCaseSuccessor()->removePredecessor(BB);
362 BasicBlock *Succ = CI->getCaseSuccessor();
363 Succ->removePredecessor(BB);
358364 CI = SI->removeCase(CI);
359365 CE = SI->case_end();
360366
364370
365371 ++NumDeadCases;
366372 Changed = true;
373 if (--SuccessorsCount[Succ] == 0)
374 DT->deleteEdge(BB, Succ);
367375 continue;
368376 }
369377 if (State == LazyValueInfo::True) {
380388 ++CI;
381389 }
382390
383 if (Changed)
391 if (Changed) {
384392 // If the switch has been simplified to the point where it can be replaced
385393 // by a branch then do so now.
386 ConstantFoldTerminator(BB);
394 DeferredDominance DDT(*DT);
395 ConstantFoldTerminator(BB, /*DeleteDeadConditions = */ false,
396 /*TLI = */ nullptr, &DDT);
397 DDT.flush();
398 }
387399
388400 return Changed;
389401 }
721733 Instruction *Term = BB->getTerminator();
722734 switch (Term->getOpcode()) {
723735 case Instruction::Switch:
724 BBChanged |= processSwitch(cast(Term), LVI);
736 BBChanged |= processSwitch(cast(Term), LVI, DT);
725737 break;
726738 case Instruction::Ret: {
727739 auto *RI = cast(Term);
766778 return PreservedAnalyses::all();
767779 PreservedAnalyses PA;
768780 PA.preserve();
781 PA.preserve();
769782 return PA;
770783 }
144144 ; CHECK-NEXT: Lazy Value Information Analysis
145145 ; CHECK-NEXT: Jump Threading
146146 ; CHECK-NEXT: Value Propagation
147 ; CHECK-NEXT: Dominator Tree Construction
148147 ; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
149148 ; CHECK-NEXT: Function Alias Analysis Results
150149 ; CHECK-NEXT: Memory Dependence Analysis
148148 ; CHECK-NEXT: Lazy Value Information Analysis
149149 ; CHECK-NEXT: Jump Threading
150150 ; CHECK-NEXT: Value Propagation
151 ; CHECK-NEXT: Dominator Tree Construction
152151 ; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
153152 ; CHECK-NEXT: Function Alias Analysis Results
154153 ; CHECK-NEXT: Memory Dependence Analysis
130130 ; CHECK-NEXT: Lazy Value Information Analysis
131131 ; CHECK-NEXT: Jump Threading
132132 ; CHECK-NEXT: Value Propagation
133 ; CHECK-NEXT: Dominator Tree Construction
134133 ; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
135134 ; CHECK-NEXT: Function Alias Analysis Results
136135 ; CHECK-NEXT: Memory Dependence Analysis