1//===- ADCE.cpp - Code to perform dead code elimination -------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the Aggressive Dead Code Elimination pass. This pass
10// optimistically assumes that all instructions are dead until proven otherwise,
11// allowing it to eliminate dead computations that other DCE passes do not
12// catch, particularly involving loop computations.
13//
14//===----------------------------------------------------------------------===//
15
16#include "llvm/Transforms/Scalar/ADCE.h"
17#include "llvm/ADT/DenseMap.h"
18#include "llvm/ADT/DepthFirstIterator.h"
19#include "llvm/ADT/GraphTraits.h"
20#include "llvm/ADT/PostOrderIterator.h"
21#include "llvm/ADT/SetVector.h"
22#include "llvm/ADT/SmallPtrSet.h"
23#include "llvm/ADT/SmallVector.h"
24#include "llvm/ADT/Statistic.h"
25#include "llvm/Analysis/CFG.h"
26#include "llvm/Analysis/DomTreeUpdater.h"
27#include "llvm/Analysis/GlobalsModRef.h"
28#include "llvm/Analysis/IteratedDominanceFrontier.h"
29#include "llvm/Analysis/MemorySSA.h"
30#include "llvm/Analysis/PostDominators.h"
31#include "llvm/IR/BasicBlock.h"
32#include "llvm/IR/CFG.h"
33#include "llvm/IR/DebugInfo.h"
34#include "llvm/IR/DebugInfoMetadata.h"
35#include "llvm/IR/DebugLoc.h"
36#include "llvm/IR/Dominators.h"
37#include "llvm/IR/Function.h"
38#include "llvm/IR/IRBuilder.h"
39#include "llvm/IR/InstIterator.h"
40#include "llvm/IR/Instruction.h"
41#include "llvm/IR/Instructions.h"
42#include "llvm/IR/IntrinsicInst.h"
43#include "llvm/IR/PassManager.h"
44#include "llvm/IR/Use.h"
45#include "llvm/IR/Value.h"
46#include "llvm/ProfileData/InstrProf.h"
47#include "llvm/Support/Casting.h"
48#include "llvm/Support/CommandLine.h"
49#include "llvm/Support/Debug.h"
50#include "llvm/Support/raw_ostream.h"
51#include "llvm/Transforms/Utils/Local.h"
52#include <cassert>
53#include <cstddef>
54#include <utility>
55
56using namespace llvm;
57
58#define DEBUG_TYPE "adce"
59
60STATISTIC(NumRemoved, "Number of instructions removed");
61STATISTIC(NumBranchesRemoved, "Number of branch instructions removed");
62
63// This is a temporary option until we change the interface to this pass based
64// on optimization level.
65static cl::opt<bool> RemoveControlFlowFlag("adce-remove-control-flow",
66 cl::init(Val: true), cl::Hidden);
67
68// This option enables removing of may-be-infinite loops which have no other
69// effect.
70static cl::opt<bool> RemoveLoops("adce-remove-loops", cl::init(Val: false),
71 cl::Hidden);
72
73namespace {
74
75/// Information about basic blocks relevant to dead code elimination.
76struct BlockInfoType {
77 /// True when this block contains a live instructions.
78 bool Live = false;
79
80 /// True when this block is known to have live PHI nodes.
81 bool HasLivePhiNodes = false;
82
83 /// Control dependence sources need to be live for this block.
84 bool CFLive = false;
85
86 /// Post-order numbering of reverse control flow graph.
87 unsigned PostOrder = 0;
88};
89
90struct ADCEChanged {
91 bool ChangedAnything = false;
92 bool ChangedNonDebugInstr = false;
93 bool ChangedControlFlow = false;
94};
95
96class AggressiveDeadCodeElimination {
97 Function &F;
98
99 // ADCE does not use DominatorTree per se, but it updates it to preserve the
100 // analysis.
101 DominatorTree *DT;
102 PostDominatorTree &PDT;
103
104 /// Mapping of blocks to associated information, indexed by block number.
105 SmallVector<BlockInfoType> BlockInfo;
106
107 /// Set of live instructions.
108 SmallPtrSet<Instruction *, 32> LiveInst;
109 bool isLive(Instruction *I) { return LiveInst.contains(Ptr: I); }
110
111 /// Instructions known to be live where we need to mark
112 /// reaching definitions as live.
113 SmallVector<Instruction *, 128> Worklist;
114
115 /// Debug info scopes around a live instruction.
116 SmallPtrSet<const Metadata *, 32> AliveScopes;
117
118 /// Set of blocks with not known to have live terminators.
119 SmallSetVector<BasicBlock *, 16> BlocksWithDeadTerminators;
120
121 /// The set of blocks which we have determined whose control
122 /// dependence sources must be live and which have not had
123 /// those dependences analyzed.
124 SmallPtrSet<BasicBlock *, 16> NewLiveBlocks;
125
126 /// Set up auxiliary data structures for Instructions and BasicBlocks and
127 /// initialize the Worklist to the set of must-be-live Instruscions.
128 void initialize();
129
130 BlockInfoType &getBlockInfo(BasicBlock *BB) {
131 return BlockInfo[BB->getNumber()];
132 }
133
134 /// Return true for operations which are always treated as live.
135 bool isAlwaysLive(Instruction &I);
136
137 /// Return true for instrumentation instructions for value profiling.
138 bool isInstrumentsConstant(Instruction &I);
139
140 /// Propagate liveness to reaching definitions.
141 void markLiveInstructions();
142
143 /// Mark an instruction as live.
144 void markLive(Instruction *I);
145
146 /// Mark a block as live.
147 void markLive(BasicBlock *BB);
148
149 /// Mark terminators of control predecessors of a PHI node live.
150 void markPhiLive(PHINode *PN);
151
152 /// Record the Debug Scopes which surround live debug information.
153 void collectLiveScopes(const DILocalScope &LS);
154 void collectLiveScopes(const DILocation &DL);
155
156 /// Analyze dead branches to find those whose branches are the sources
157 /// of control dependences impacting a live block. Those branches are
158 /// marked live.
159 void markLiveBranchesFromControlDependences();
160
161 /// Remove instructions not marked live, return if any instruction was
162 /// removed.
163 ADCEChanged removeDeadInstructions();
164
165 /// Identify connected sections of the control flow graph which have
166 /// dead terminators and rewrite the control flow graph to remove them.
167 bool updateDeadRegions();
168
169 /// Set the BlockInfo::PostOrder field based on a post-order
170 /// numbering of the reverse control flow graph.
171 void computeReversePostOrder();
172
173 /// Make the terminator of this block an unconditional branch to \p Target.
174 void makeUnconditional(BasicBlock *BB, BasicBlock *Target);
175
176public:
177 AggressiveDeadCodeElimination(Function &F, DominatorTree *DT,
178 PostDominatorTree &PDT)
179 : F(F), DT(DT), PDT(PDT) {}
180
181 ADCEChanged performDeadCodeElimination();
182};
183
184} // end anonymous namespace
185
186ADCEChanged AggressiveDeadCodeElimination::performDeadCodeElimination() {
187 initialize();
188 markLiveInstructions();
189 return removeDeadInstructions();
190}
191
192void AggressiveDeadCodeElimination::initialize() {
193 BlockInfo.resize(N: F.getMaxBlockNumber());
194 size_t NumInsts = 0;
195 for (auto &BB : F)
196 NumInsts += BB.size();
197 LiveInst.reserve(NewNumEntries: NumInsts);
198
199 // Collect the set of "root" instructions that are known live.
200 for (Instruction &I : instructions(F))
201 if (isAlwaysLive(I))
202 markLive(I: &I);
203
204 if (!RemoveControlFlowFlag)
205 return;
206
207 if (!RemoveLoops) {
208 // Mark all terminators that have backedges as live.
209 SmallVector<std::pair<const BasicBlock *, const BasicBlock *>> Backedges;
210 FindFunctionBackedges(F, Result&: Backedges);
211 for (const auto &[Src, Dst] : Backedges)
212 markLive(I: const_cast<Instruction *>(Src->getTerminator()));
213 }
214
215 // Mark blocks live if there is no path from the block to a
216 // return of the function.
217 // We do this by seeing which of the postdomtree root children exit the
218 // program, and for all others, mark the subtree live.
219 for (const auto &PDTChild : children<DomTreeNode *>(G: PDT.getRootNode())) {
220 auto *BB = PDTChild->getBlock();
221 // Real function return
222 if (isa<ReturnInst>(Val: BB->back())) {
223 LLVM_DEBUG(dbgs() << "post-dom root child is a return: " << BB->getName()
224 << '\n';);
225 continue;
226 }
227
228 // This child is something else, like an infinite loop.
229 for (auto *DFNode : depth_first(G: PDTChild))
230 markLive(I: &DFNode->getBlock()->back());
231 }
232
233 // Treat the entry block as always live
234 auto *BB = &F.getEntryBlock();
235 auto &EntryInfo = getBlockInfo(BB);
236 EntryInfo.Live = true;
237 if (isa<UncondBrInst>(Val: BB->back()))
238 markLive(I: &BB->back());
239
240 // Build initial collection of blocks with dead terminators
241 for (auto &BB : F)
242 if (!isLive(I: &BB.back()))
243 BlocksWithDeadTerminators.insert(X: &BB);
244}
245
246bool AggressiveDeadCodeElimination::isAlwaysLive(Instruction &I) {
247 // TODO -- use llvm::isInstructionTriviallyDead
248 if (I.isEHPad() || I.mayHaveSideEffects()) {
249 // Skip any value profile instrumentation calls if they are
250 // instrumenting constants.
251 if (isInstrumentsConstant(I))
252 return false;
253 return true;
254 }
255 if (!I.isTerminator())
256 return false;
257 if (RemoveControlFlowFlag && isa<UncondBrInst, CondBrInst, SwitchInst>(Val: I))
258 return false;
259 return true;
260}
261
262// Check if this instruction is a runtime call for value profiling and
263// if it's instrumenting a constant.
264bool AggressiveDeadCodeElimination::isInstrumentsConstant(Instruction &I) {
265 // TODO -- move this test into llvm::isInstructionTriviallyDead
266 if (CallInst *CI = dyn_cast<CallInst>(Val: &I))
267 if (Function *Callee = CI->getCalledFunction())
268 if (Callee->getName() == getInstrProfValueProfFuncName())
269 if (isa<Constant>(Val: CI->getArgOperand(i: 0)))
270 return true;
271 return false;
272}
273
274void AggressiveDeadCodeElimination::markLiveInstructions() {
275 // Propagate liveness backwards to operands.
276 do {
277 // Worklist holds newly discovered live instructions
278 // where we need to mark the inputs as live.
279 while (!Worklist.empty()) {
280 Instruction *LiveInst = Worklist.pop_back_val();
281 LLVM_DEBUG(dbgs() << "work live: "; LiveInst->dump(););
282
283 for (Use &OI : LiveInst->operands())
284 if (Instruction *Inst = dyn_cast<Instruction>(Val&: OI))
285 markLive(I: Inst);
286
287 if (auto *PN = dyn_cast<PHINode>(Val: LiveInst))
288 markPhiLive(PN);
289 }
290
291 // After data flow liveness has been identified, examine which branch
292 // decisions are required to determine live instructions are executed.
293 markLiveBranchesFromControlDependences();
294
295 } while (!Worklist.empty());
296}
297
298void AggressiveDeadCodeElimination::markLive(Instruction *I) {
299 auto [It, Inserted] = LiveInst.insert(Ptr: I);
300 if (!Inserted)
301 return;
302
303 LLVM_DEBUG(dbgs() << "mark live: "; I->dump());
304 Worklist.push_back(Elt: I);
305
306 // Collect the live debug info scopes attached to this instruction.
307 if (const DILocation *DL = I->getDebugLoc())
308 collectLiveScopes(DL: *DL);
309
310 // Mark the containing block live
311 BasicBlock *BB = I->getParent();
312 if (I == &BB->back()) {
313 BlocksWithDeadTerminators.remove(X: BB);
314 // For live terminators, mark destination blocks
315 // live to preserve this control flow edges.
316 if (!isa<UncondBrInst>(Val: I))
317 for (auto *Succ : I->successors())
318 markLive(BB: Succ);
319 }
320 markLive(BB);
321}
322
323void AggressiveDeadCodeElimination::markLive(BasicBlock *BB) {
324 auto &BBInfo = BlockInfo[BB->getNumber()];
325 if (BBInfo.Live)
326 return;
327 LLVM_DEBUG(dbgs() << "mark block live: " << BB->getName() << '\n');
328 BBInfo.Live = true;
329 if (!BBInfo.CFLive) {
330 BBInfo.CFLive = true;
331 NewLiveBlocks.insert(Ptr: BB);
332 }
333
334 // Mark unconditional branches at the end of live
335 // blocks as live since there is no work to do for them later
336 if (isa<UncondBrInst>(Val: BB->back()))
337 markLive(I: &BB->back());
338}
339
340void AggressiveDeadCodeElimination::collectLiveScopes(const DILocalScope &LS) {
341 if (!AliveScopes.insert(Ptr: &LS).second)
342 return;
343
344 if (isa<DISubprogram>(Val: LS))
345 return;
346
347 // Tail-recurse through the scope chain.
348 collectLiveScopes(LS: cast<DILocalScope>(Val&: *LS.getScope()));
349}
350
351void AggressiveDeadCodeElimination::collectLiveScopes(const DILocation &DL) {
352 // Even though DILocations are not scopes, shove them into AliveScopes so we
353 // don't revisit them.
354 if (!AliveScopes.insert(Ptr: &DL).second)
355 return;
356
357 // Collect live scopes from the scope chain.
358 collectLiveScopes(LS: *DL.getScope());
359
360 // Tail-recurse through the inlined-at chain.
361 if (const DILocation *IA = DL.getInlinedAt())
362 collectLiveScopes(DL: *IA);
363}
364
365void AggressiveDeadCodeElimination::markPhiLive(PHINode *PN) {
366 auto &Info = getBlockInfo(BB: PN->getParent());
367 // Only need to check this once per block.
368 if (Info.HasLivePhiNodes)
369 return;
370 Info.HasLivePhiNodes = true;
371
372 // If a predecessor block is not live, mark it as control-flow live
373 // which will trigger marking live branches upon which
374 // that block is control dependent.
375 for (auto *PredBB : predecessors(BB: PN->getParent())) {
376 auto &Info = getBlockInfo(BB: PredBB);
377 if (!Info.CFLive) {
378 Info.CFLive = true;
379 NewLiveBlocks.insert(Ptr: PredBB);
380 }
381 }
382}
383
384void AggressiveDeadCodeElimination::markLiveBranchesFromControlDependences() {
385 if (BlocksWithDeadTerminators.empty())
386 return;
387
388 LLVM_DEBUG({
389 dbgs() << "new live blocks:\n";
390 for (auto *BB : NewLiveBlocks)
391 dbgs() << "\t" << BB->getName() << '\n';
392 dbgs() << "dead terminator blocks:\n";
393 for (auto *BB : BlocksWithDeadTerminators)
394 dbgs() << "\t" << BB->getName() << '\n';
395 });
396
397 // The dominance frontier of a live block X in the reverse
398 // control graph is the set of blocks upon which X is control
399 // dependent. The following sequence computes the set of blocks
400 // which currently have dead terminators that are control
401 // dependence sources of a block which is in NewLiveBlocks.
402
403 const SmallPtrSet<BasicBlock *, 16> BWDT(llvm::from_range,
404 BlocksWithDeadTerminators);
405 SmallVector<BasicBlock *, 32> IDFBlocks;
406 ReverseIDFCalculator IDFs(PDT);
407 IDFs.setDefiningBlocks(NewLiveBlocks);
408 IDFs.setLiveInBlocks(BWDT);
409 IDFs.calculate(IDFBlocks);
410 NewLiveBlocks.clear();
411
412 // Dead terminators which control live blocks are now marked live.
413 for (auto *BB : IDFBlocks) {
414 LLVM_DEBUG(dbgs() << "live control in: " << BB->getName() << '\n');
415 markLive(I: BB->getTerminator());
416 }
417}
418
419//===----------------------------------------------------------------------===//
420//
421// Routines to update the CFG and SSA information before removing dead code.
422//
423//===----------------------------------------------------------------------===//
424ADCEChanged AggressiveDeadCodeElimination::removeDeadInstructions() {
425 ADCEChanged Changed;
426 // Updates control and dataflow around dead blocks
427 Changed.ChangedControlFlow = updateDeadRegions();
428
429 LLVM_DEBUG({
430 for (Instruction &I : instructions(F)) {
431 // Check if the instruction is alive.
432 if (isLive(&I))
433 continue;
434
435 if (auto *DII = dyn_cast<DbgVariableIntrinsic>(&I)) {
436 // Check if the scope of this variable location is alive.
437 if (AliveScopes.count(DII->getDebugLoc()->getScope()))
438 continue;
439
440 // If intrinsic is pointing at a live SSA value, there may be an
441 // earlier optimization bug: if we know the location of the variable,
442 // why isn't the scope of the location alive?
443 for (Value *V : DII->location_ops()) {
444 if (Instruction *II = dyn_cast<Instruction>(V)) {
445 if (isLive(II)) {
446 dbgs() << "Dropping debug info for " << *DII << "\n";
447 break;
448 }
449 }
450 }
451 }
452 }
453 });
454
455 // The inverse of the live set is the dead set. These are those instructions
456 // that have no side effects and do not influence the control flow or return
457 // value of the function, and may therefore be deleted safely.
458 // NOTE: We reuse the Worklist vector here for memory efficiency.
459 for (Instruction &I : llvm::reverse(C: instructions(F))) {
460 // With "RemoveDIs" debug-info stored in DbgVariableRecord objects,
461 // debug-info attached to this instruction, and drop any for scopes that
462 // aren't alive, like the rest of this loop does. Extending support to
463 // assignment tracking is future work.
464 for (DbgRecord &DR : make_early_inc_range(Range: I.getDbgRecordRange())) {
465 // Avoid removing a DVR that is linked to instructions because it holds
466 // information about an existing store.
467 if (DbgVariableRecord *DVR = dyn_cast<DbgVariableRecord>(Val: &DR);
468 DVR && DVR->isDbgAssign())
469 if (!at::getAssignmentInsts(DVR).empty())
470 continue;
471 if (AliveScopes.count(Ptr: DR.getDebugLoc()->getScope()))
472 continue;
473 I.dropOneDbgRecord(I: &DR);
474 }
475
476 // Check if the instruction is alive.
477 if (isLive(I: &I))
478 continue;
479
480 Changed.ChangedNonDebugInstr = true;
481
482 // Prepare to delete.
483 Worklist.push_back(Elt: &I);
484 salvageDebugInfo(I);
485 }
486
487 for (Instruction *&I : Worklist)
488 I->dropAllReferences();
489
490 for (Instruction *&I : Worklist) {
491 ++NumRemoved;
492 I->eraseFromParent();
493 }
494
495 Changed.ChangedAnything = Changed.ChangedControlFlow || !Worklist.empty();
496
497 return Changed;
498}
499
500// A dead region is the set of dead blocks with a common live post-dominator.
501bool AggressiveDeadCodeElimination::updateDeadRegions() {
502 LLVM_DEBUG({
503 dbgs() << "final dead terminator blocks: " << '\n';
504 for (auto *BB : BlocksWithDeadTerminators)
505 dbgs() << '\t' << BB->getName()
506 << (getBlockInfo(BB).Live ? " LIVE\n" : "\n");
507 });
508
509 // Don't compute the post ordering unless we needed it.
510 bool HavePostOrder = false;
511 bool Changed = false;
512 SmallVector<DominatorTree::UpdateType, 10> DeletedEdges;
513
514 for (auto *BB : BlocksWithDeadTerminators) {
515 if (isa<UncondBrInst>(Val: BB->back())) {
516 LiveInst.insert(Ptr: &BB->back());
517 continue;
518 }
519
520 if (!HavePostOrder) {
521 computeReversePostOrder();
522 HavePostOrder = true;
523 }
524
525 // Add an unconditional branch to the successor closest to the
526 // end of the function which insures a path to the exit for each
527 // live edge.
528 BasicBlock *PreferredSucc = nullptr;
529 unsigned PreferredSuccPostOrder = 0;
530 for (auto *Succ : successors(BB)) {
531 unsigned SuccPostOrder = BlockInfo[Succ->getNumber()].PostOrder;
532 if (PreferredSuccPostOrder < SuccPostOrder) {
533 PreferredSucc = Succ;
534 PreferredSuccPostOrder = SuccPostOrder;
535 }
536 }
537 assert((PreferredSucc && PreferredSuccPostOrder > 0) &&
538 "Failed to find safe successor for dead branch");
539
540 // Collect removed successors to update the (Post)DominatorTrees.
541 SmallPtrSet<BasicBlock *, 4> RemovedSuccessors;
542 bool First = true;
543 for (auto *Succ : successors(BB)) {
544 if (!First || Succ != PreferredSucc) {
545 Succ->removePredecessor(Pred: BB);
546 RemovedSuccessors.insert(Ptr: Succ);
547 } else
548 First = false;
549 }
550 makeUnconditional(BB, Target: PreferredSucc);
551
552 // Inform the dominators about the deleted CFG edges.
553 for (auto *Succ : RemovedSuccessors) {
554 // It might have happened that the same successor appeared multiple times
555 // and the CFG edge wasn't really removed.
556 if (Succ != PreferredSucc) {
557 LLVM_DEBUG(dbgs() << "ADCE: (Post)DomTree edge enqueued for deletion"
558 << BB->getName() << " -> " << Succ->getName()
559 << "\n");
560 DeletedEdges.push_back(Elt: {DominatorTree::Delete, BB, Succ});
561 }
562 }
563
564 NumBranchesRemoved += 1;
565 Changed = true;
566 }
567
568 if (!DeletedEdges.empty())
569 DomTreeUpdater(DT, &PDT, DomTreeUpdater::UpdateStrategy::Eager)
570 .applyUpdates(Updates: DeletedEdges);
571
572 return Changed;
573}
574
575// reverse top-sort order
576void AggressiveDeadCodeElimination::computeReversePostOrder() {
577 // This provides a post-order numbering of the reverse control flow graph
578 // Note that it is incomplete in the presence of infinite loops but we don't
579 // need numbers blocks which don't reach the end of the functions since
580 // all branches in those blocks are forced live.
581
582 // For each block without successors, extend the DFS from the block
583 // backward through the graph
584 SmallPtrSet<BasicBlock*, 16> Visited;
585 unsigned PostOrder = 0;
586 for (auto &BB : F) {
587 if (!succ_empty(BB: &BB))
588 continue;
589 for (BasicBlock *Block : inverse_post_order_ext(G: &BB,S&: Visited))
590 getBlockInfo(BB: Block).PostOrder = PostOrder++;
591 }
592}
593
594void AggressiveDeadCodeElimination::makeUnconditional(BasicBlock *BB,
595 BasicBlock *Target) {
596 Instruction *PredTerm = BB->getTerminator();
597 // Collect the live debug info scopes attached to this instruction.
598 if (const DILocation *DL = PredTerm->getDebugLoc())
599 collectLiveScopes(DL: *DL);
600
601 // Just mark live an existing unconditional branch
602 if (auto *BI = dyn_cast<UncondBrInst>(Val: PredTerm)) {
603 BI->setSuccessor(Target);
604 LiveInst.insert(Ptr: PredTerm);
605 return;
606 }
607 LLVM_DEBUG(dbgs() << "making unconditional " << BB->getName() << '\n');
608 NumBranchesRemoved += 1;
609 IRBuilder<> Builder(PredTerm);
610 auto *NewTerm = Builder.CreateBr(Dest: Target);
611 LiveInst.insert(Ptr: NewTerm);
612 if (const DILocation *DL = PredTerm->getDebugLoc())
613 NewTerm->setDebugLoc(DL);
614 PredTerm->eraseFromParent();
615}
616
617//===----------------------------------------------------------------------===//
618//
619// Pass Manager integration code
620//
621//===----------------------------------------------------------------------===//
622PreservedAnalyses ADCEPass::run(Function &F, FunctionAnalysisManager &FAM) {
623 // ADCE does not need DominatorTree, but require DominatorTree here
624 // to update analysis if it is already available.
625 auto *DT = FAM.getCachedResult<DominatorTreeAnalysis>(IR&: F);
626 auto &PDT = FAM.getResult<PostDominatorTreeAnalysis>(IR&: F);
627 ADCEChanged Changed =
628 AggressiveDeadCodeElimination(F, DT, PDT).performDeadCodeElimination();
629 if (!Changed.ChangedAnything)
630 return PreservedAnalyses::all();
631
632 PreservedAnalyses PA;
633 if (!Changed.ChangedControlFlow) {
634 PA.preserveSet<CFGAnalyses>();
635 if (!Changed.ChangedNonDebugInstr) {
636 // Only removing debug instructions does not affect MemorySSA.
637 //
638 // Therefore we preserve MemorySSA when only removing debug instructions
639 // since otherwise later passes may behave differently which then makes
640 // the presence of debug info affect code generation.
641 PA.preserve<MemorySSAAnalysis>();
642 }
643 }
644 PA.preserve<DominatorTreeAnalysis>();
645 PA.preserve<PostDominatorTreeAnalysis>();
646
647 return PA;
648}
649