Run early if-conversion in domtree post-order.
[oota-llvm.git] / lib / CodeGen / EarlyIfConversion.cpp
1 //===-- EarlyIfConversion.cpp - If-conversion on SSA form machine code ----===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Early if-conversion is for out-of-order CPUs that don't have a lot of
11 // predicable instructions. The goal is to eliminate conditional branches that
12 // may mispredict.
13 //
14 // Instructions from both sides of the branch are executed specutatively, and a
15 // cmov instruction selects the result.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #define DEBUG_TYPE "early-ifcvt"
20 #include "llvm/Function.h"
21 #include "llvm/ADT/BitVector.h"
22 #include "llvm/ADT/PostOrderIterator.h"
23 #include "llvm/ADT/SetVector.h"
24 #include "llvm/ADT/SmallPtrSet.h"
25 #include "llvm/ADT/SparseSet.h"
26 #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
27 #include "llvm/CodeGen/MachineDominators.h"
28 #include "llvm/CodeGen/MachineFunction.h"
29 #include "llvm/CodeGen/MachineFunctionPass.h"
30 #include "llvm/CodeGen/MachineRegisterInfo.h"
31 #include "llvm/CodeGen/Passes.h"
32 #include "llvm/Target/TargetInstrInfo.h"
33 #include "llvm/Target/TargetRegisterInfo.h"
34 #include "llvm/Support/CommandLine.h"
35 #include "llvm/Support/Debug.h"
36 #include "llvm/Support/raw_ostream.h"
37
38 using namespace llvm;
39
40 // Absolute maximum number of instructions allowed per speculated block.
41 // This bypasses all other heuristics, so it should be set fairly high.
42 static cl::opt<unsigned>
43 BlockInstrLimit("early-ifcvt-limit", cl::init(30), cl::Hidden,
44   cl::desc("Maximum number of instructions per speculated block."));
45
46 // Stress testing mode - disable heuristics.
47 static cl::opt<bool> Stress("stress-early-ifcvt", cl::Hidden,
48   cl::desc("Turn all knobs to 11"));
49
50 typedef SmallSetVector<MachineBasicBlock*, 8> BlockSetVector;
51
52 //===----------------------------------------------------------------------===//
53 //                                 SSAIfConv
54 //===----------------------------------------------------------------------===//
55 //
56 // The SSAIfConv class performs if-conversion on SSA form machine code after
57 // determining if it is possible. The class contains no heuristics; external
58 // code should be used to determine when if-conversion is a good idea.
59 //
60 // SSAIfConv can convert both triangles and diamonds:
61 //
62 //   Triangle: Head              Diamond: Head
63 //              | \                       /  \_
64 //              |  \                     /    |
65 //              |  [TF]BB              FBB    TBB
66 //              |  /                     \    /
67 //              | /                       \  /
68 //             Tail                       Tail
69 //
70 // Instructions in the conditional blocks TBB and/or FBB are spliced into the
71 // Head block, and phis in the Tail block are converted to select instructions.
72 //
73 namespace {
74 class SSAIfConv {
75   const TargetInstrInfo *TII;
76   const TargetRegisterInfo *TRI;
77   MachineRegisterInfo *MRI;
78
79 public:
80   /// The block containing the conditional branch.
81   MachineBasicBlock *Head;
82
83   /// The block containing phis after the if-then-else.
84   MachineBasicBlock *Tail;
85
86   /// The 'true' conditional block as determined by AnalyzeBranch.
87   MachineBasicBlock *TBB;
88
89   /// The 'false' conditional block as determined by AnalyzeBranch.
90   MachineBasicBlock *FBB;
91
92   /// isTriangle - When there is no 'else' block, either TBB or FBB will be
93   /// equal to Tail.
94   bool isTriangle() const { return TBB == Tail || FBB == Tail; }
95
96   /// Information about each phi in the Tail block.
97   struct PHIInfo {
98     MachineInstr *PHI;
99     unsigned TReg, FReg;
100     // Latencies from Cond+Branch, TReg, and FReg to DstReg.
101     int CondCycles, TCycles, FCycles;
102
103     PHIInfo(MachineInstr *phi)
104       : PHI(phi), TReg(0), FReg(0), CondCycles(0), TCycles(0), FCycles(0) {}
105   };
106
107   SmallVector<PHIInfo, 8> PHIs;
108
109 private:
110   /// The branch condition determined by AnalyzeBranch.
111   SmallVector<MachineOperand, 4> Cond;
112
113   /// Instructions in Head that define values used by the conditional blocks.
114   /// The hoisted instructions must be inserted after these instructions.
115   SmallPtrSet<MachineInstr*, 8> InsertAfter;
116
117   /// Register units clobbered by the conditional blocks.
118   BitVector ClobberedRegUnits;
119
120   // Scratch pad for findInsertionPoint.
121   SparseSet<unsigned> LiveRegUnits;
122
123   /// Insertion point in Head for speculatively executed instructions form TBB
124   /// and FBB.
125   MachineBasicBlock::iterator InsertionPoint;
126
127   /// Return true if all non-terminator instructions in MBB can be safely
128   /// speculated.
129   bool canSpeculateInstrs(MachineBasicBlock *MBB);
130
131   /// Find a valid insertion point in Head.
132   bool findInsertionPoint();
133
134 public:
135   /// runOnMachineFunction - Initialize per-function data structures.
136   void runOnMachineFunction(MachineFunction &MF) {
137     TII = MF.getTarget().getInstrInfo();
138     TRI = MF.getTarget().getRegisterInfo();
139     MRI = &MF.getRegInfo();
140     LiveRegUnits.clear();
141     LiveRegUnits.setUniverse(TRI->getNumRegUnits());
142     ClobberedRegUnits.clear();
143     ClobberedRegUnits.resize(TRI->getNumRegUnits());
144   }
145
146   /// canConvertIf - If the sub-CFG headed by MBB can be if-converted,
147   /// initialize the internal state, and return true.
148   bool canConvertIf(MachineBasicBlock *MBB);
149
150   /// convertIf - If-convert the last block passed to canConvertIf(), assuming
151   /// it is possible. Add any erased blocks to RemovedBlocks.
152   void convertIf(SmallVectorImpl<MachineBasicBlock*> &RemovedBlocks);
153 };
154 } // end anonymous namespace
155
156
157 /// canSpeculateInstrs - Returns true if all the instructions in MBB can safely
158 /// be speculated. The terminators are not considered.
159 ///
160 /// If instructions use any values that are defined in the head basic block,
161 /// the defining instructions are added to InsertAfter.
162 ///
163 /// Any clobbered regunits are added to ClobberedRegUnits.
164 ///
165 bool SSAIfConv::canSpeculateInstrs(MachineBasicBlock *MBB) {
166   // Reject any live-in physregs. It's probably CPSR/EFLAGS, and very hard to
167   // get right.
168   if (!MBB->livein_empty()) {
169     DEBUG(dbgs() << "BB#" << MBB->getNumber() << " has live-ins.\n");
170     return false;
171   }
172
173   unsigned InstrCount = 0;
174
175   // Check all instructions, except the terminators. It is assumed that
176   // terminators never have side effects or define any used register values.
177   for (MachineBasicBlock::iterator I = MBB->begin(),
178        E = MBB->getFirstTerminator(); I != E; ++I) {
179     if (I->isDebugValue())
180       continue;
181
182     if (++InstrCount > BlockInstrLimit && !Stress) {
183       DEBUG(dbgs() << "BB#" << MBB->getNumber() << " has more than "
184                    << BlockInstrLimit << " instructions.\n");
185       return false;
186     }
187
188     // There shouldn't normally be any phis in a single-predecessor block.
189     if (I->isPHI()) {
190       DEBUG(dbgs() << "Can't hoist: " << *I);
191       return false;
192     }
193
194     // Don't speculate loads. Note that it may be possible and desirable to
195     // speculate GOT or constant pool loads that are guaranteed not to trap,
196     // but we don't support that for now.
197     if (I->mayLoad()) {
198       DEBUG(dbgs() << "Won't speculate load: " << *I);
199       return false;
200     }
201
202     // We never speculate stores, so an AA pointer isn't necessary.
203     bool DontMoveAcrossStore = true;
204     if (!I->isSafeToMove(TII, 0, DontMoveAcrossStore)) {
205       DEBUG(dbgs() << "Can't speculate: " << *I);
206       return false;
207     }
208
209     // Check for any dependencies on Head instructions.
210     for (MIOperands MO(I); MO.isValid(); ++MO) {
211       if (MO->isRegMask()) {
212         DEBUG(dbgs() << "Won't speculate regmask: " << *I);
213         return false;
214       }
215       if (!MO->isReg())
216         continue;
217       unsigned Reg = MO->getReg();
218
219       // Remember clobbered regunits.
220       if (MO->isDef() && TargetRegisterInfo::isPhysicalRegister(Reg))
221         for (MCRegUnitIterator Units(Reg, TRI); Units.isValid(); ++Units)
222           ClobberedRegUnits.set(*Units);
223
224       if (!MO->readsReg() || !TargetRegisterInfo::isVirtualRegister(Reg))
225         continue;
226       MachineInstr *DefMI = MRI->getVRegDef(Reg);
227       if (!DefMI || DefMI->getParent() != Head)
228         continue;
229       if (InsertAfter.insert(DefMI))
230         DEBUG(dbgs() << "BB#" << MBB->getNumber() << " depends on " << *DefMI);
231       if (DefMI->isTerminator()) {
232         DEBUG(dbgs() << "Can't insert instructions below terminator.\n");
233         return false;
234       }
235     }
236   }
237   return true;
238 }
239
240
241 /// Find an insertion point in Head for the speculated instructions. The
242 /// insertion point must be:
243 ///
244 /// 1. Before any terminators.
245 /// 2. After any instructions in InsertAfter.
246 /// 3. Not have any clobbered regunits live.
247 ///
248 /// This function sets InsertionPoint and returns true when successful, it
249 /// returns false if no valid insertion point could be found.
250 ///
251 bool SSAIfConv::findInsertionPoint() {
252   // Keep track of live regunits before the current position.
253   // Only track RegUnits that are also in ClobberedRegUnits.
254   LiveRegUnits.clear();
255   SmallVector<unsigned, 8> Reads;
256   MachineBasicBlock::iterator FirstTerm = Head->getFirstTerminator();
257   MachineBasicBlock::iterator I = Head->end();
258   MachineBasicBlock::iterator B = Head->begin();
259   while (I != B) {
260     --I;
261     // Some of the conditional code depends in I.
262     if (InsertAfter.count(I)) {
263       DEBUG(dbgs() << "Can't insert code after " << *I);
264       return false;
265     }
266
267     // Update live regunits.
268     for (MIOperands MO(I); MO.isValid(); ++MO) {
269       // We're ignoring regmask operands. That is conservatively correct.
270       if (!MO->isReg())
271         continue;
272       unsigned Reg = MO->getReg();
273       if (!TargetRegisterInfo::isPhysicalRegister(Reg))
274         continue;
275       // I clobbers Reg, so it isn't live before I.
276       if (MO->isDef())
277         for (MCRegUnitIterator Units(Reg, TRI); Units.isValid(); ++Units)
278           LiveRegUnits.erase(*Units);
279       // Unless I reads Reg.
280       if (MO->readsReg())
281         Reads.push_back(Reg);
282     }
283     // Anything read by I is live before I.
284     while (!Reads.empty())
285       for (MCRegUnitIterator Units(Reads.pop_back_val(), TRI); Units.isValid();
286            ++Units)
287         if (ClobberedRegUnits.test(*Units))
288           LiveRegUnits.insert(*Units);
289
290     // We can't insert before a terminator.
291     if (I != FirstTerm && I->isTerminator())
292       continue;
293
294     // Some of the clobbered registers are live before I, not a valid insertion
295     // point.
296     if (!LiveRegUnits.empty()) {
297       DEBUG({
298         dbgs() << "Would clobber";
299         for (SparseSet<unsigned>::const_iterator
300              i = LiveRegUnits.begin(), e = LiveRegUnits.end(); i != e; ++i)
301           dbgs() << ' ' << PrintRegUnit(*i, TRI);
302         dbgs() << " live before " << *I;
303       });
304       continue;
305     }
306
307     // This is a valid insertion point.
308     InsertionPoint = I;
309     DEBUG(dbgs() << "Can insert before " << *I);
310     return true;
311   }
312   DEBUG(dbgs() << "No legal insertion point found.\n");
313   return false;
314 }
315
316
317
318 /// canConvertIf - analyze the sub-cfg rooted in MBB, and return true if it is
319 /// a potential candidate for if-conversion. Fill out the internal state.
320 ///
321 bool SSAIfConv::canConvertIf(MachineBasicBlock *MBB) {
322   Head = MBB;
323   TBB = FBB = Tail = 0;
324
325   if (Head->succ_size() != 2)
326     return false;
327   MachineBasicBlock *Succ0 = Head->succ_begin()[0];
328   MachineBasicBlock *Succ1 = Head->succ_begin()[1];
329
330   // Canonicalize so Succ0 has MBB as its single predecessor.
331   if (Succ0->pred_size() != 1)
332     std::swap(Succ0, Succ1);
333
334   if (Succ0->pred_size() != 1 || Succ0->succ_size() != 1)
335     return false;
336
337   // We could support additional Tail predecessors by updating phis instead of
338   // eliminating them. Let's see an example where it matters first.
339   Tail = Succ0->succ_begin()[0];
340   if (Tail->pred_size() != 2)
341     return false;
342
343   // This is not a triangle.
344   if (Tail != Succ1) {
345     // Check for a diamond. We won't deal with any critical edges.
346     if (Succ1->pred_size() != 1 || Succ1->succ_size() != 1 ||
347         Succ1->succ_begin()[0] != Tail)
348       return false;
349     DEBUG(dbgs() << "\nDiamond: BB#" << Head->getNumber()
350                  << " -> BB#" << Succ0->getNumber()
351                  << "/BB#" << Succ1->getNumber()
352                  << " -> BB#" << Tail->getNumber() << '\n');
353
354     // Live-in physregs are tricky to get right when speculating code.
355     if (!Tail->livein_empty()) {
356       DEBUG(dbgs() << "Tail has live-ins.\n");
357       return false;
358     }
359   } else {
360     DEBUG(dbgs() << "\nTriangle: BB#" << Head->getNumber()
361                  << " -> BB#" << Succ0->getNumber()
362                  << " -> BB#" << Tail->getNumber() << '\n');
363   }
364
365   // This is a triangle or a diamond.
366   // If Tail doesn't have any phis, there must be side effects.
367   if (Tail->empty() || !Tail->front().isPHI()) {
368     DEBUG(dbgs() << "No phis in tail.\n");
369     return false;
370   }
371
372   // The branch we're looking to eliminate must be analyzable.
373   Cond.clear();
374   if (TII->AnalyzeBranch(*Head, TBB, FBB, Cond)) {
375     DEBUG(dbgs() << "Branch not analyzable.\n");
376     return false;
377   }
378
379   // This is weird, probably some sort of degenerate CFG.
380   if (!TBB) {
381     DEBUG(dbgs() << "AnalyzeBranch didn't find conditional branch.\n");
382     return false;
383   }
384
385   // AnalyzeBranch doesn't set FBB on a fall-through branch.
386   // Make sure it is always set.
387   FBB = TBB == Succ0 ? Succ1 : Succ0;
388
389   // Any phis in the tail block must be convertible to selects.
390   PHIs.clear();
391   MachineBasicBlock *TPred = TBB == Tail ? Head : TBB;
392   MachineBasicBlock *FPred = FBB == Tail ? Head : FBB;
393   for (MachineBasicBlock::iterator I = Tail->begin(), E = Tail->end();
394        I != E && I->isPHI(); ++I) {
395     PHIs.push_back(&*I);
396     PHIInfo &PI = PHIs.back();
397     // Find PHI operands corresponding to TPred and FPred.
398     for (unsigned i = 1; i != PI.PHI->getNumOperands(); i += 2) {
399       if (PI.PHI->getOperand(i+1).getMBB() == TPred)
400         PI.TReg = PI.PHI->getOperand(i).getReg();
401       if (PI.PHI->getOperand(i+1).getMBB() == FPred)
402         PI.FReg = PI.PHI->getOperand(i).getReg();
403     }
404     assert(TargetRegisterInfo::isVirtualRegister(PI.TReg) && "Bad PHI");
405     assert(TargetRegisterInfo::isVirtualRegister(PI.FReg) && "Bad PHI");
406
407     // Get target information.
408     if (!TII->canInsertSelect(*Head, Cond, PI.TReg, PI.FReg,
409                               PI.CondCycles, PI.TCycles, PI.FCycles)) {
410       DEBUG(dbgs() << "Can't convert: " << *PI.PHI);
411       return false;
412     }
413   }
414
415   // Check that the conditional instructions can be speculated.
416   InsertAfter.clear();
417   ClobberedRegUnits.reset();
418   if (TBB != Tail && !canSpeculateInstrs(TBB))
419     return false;
420   if (FBB != Tail && !canSpeculateInstrs(FBB))
421     return false;
422
423   // Try to find a valid insertion point for the speculated instructions in the
424   // head basic block.
425   if (!findInsertionPoint())
426     return false;
427
428   return true;
429 }
430
431
432 /// convertIf - Execute the if conversion after canConvertIf has determined the
433 /// feasibility.
434 ///
435 /// Any basic blocks erased will be added to RemovedBlocks.
436 ///
437 void SSAIfConv::convertIf(SmallVectorImpl<MachineBasicBlock*> &RemovedBlocks) {
438   assert(Head && Tail && TBB && FBB && "Call canConvertIf first.");
439
440   // Move all instructions into Head, except for the terminators.
441   if (TBB != Tail)
442     Head->splice(InsertionPoint, TBB, TBB->begin(), TBB->getFirstTerminator());
443   if (FBB != Tail)
444     Head->splice(InsertionPoint, FBB, FBB->begin(), FBB->getFirstTerminator());
445
446   MachineBasicBlock::iterator FirstTerm = Head->getFirstTerminator();
447   assert(FirstTerm != Head->end() && "No terminators");
448   DebugLoc HeadDL = FirstTerm->getDebugLoc();
449
450   // Convert all PHIs to select instructions inserted before FirstTerm.
451   for (unsigned i = 0, e = PHIs.size(); i != e; ++i) {
452     PHIInfo &PI = PHIs[i];
453     DEBUG(dbgs() << "If-converting " << *PI.PHI);
454     assert(PI.PHI->getNumOperands() == 5 && "Unexpected PHI operands.");
455     unsigned DstReg = PI.PHI->getOperand(0).getReg();
456     TII->insertSelect(*Head, FirstTerm, HeadDL, DstReg, Cond, PI.TReg, PI.FReg);
457     DEBUG(dbgs() << "          --> " << *llvm::prior(FirstTerm));
458     PI.PHI->eraseFromParent();
459     PI.PHI = 0;
460   }
461
462   // Fix up the CFG, temporarily leave Head without any successors.
463   Head->removeSuccessor(TBB);
464   Head->removeSuccessor(FBB);
465   if (TBB != Tail)
466     TBB->removeSuccessor(Tail);
467   if (FBB != Tail)
468     FBB->removeSuccessor(Tail);
469
470   // Fix up Head's terminators.
471   // It should become a single branch or a fallthrough.
472   TII->RemoveBranch(*Head);
473
474   // Erase the now empty conditional blocks. It is likely that Head can fall
475   // through to Tail, and we can join the two blocks.
476   if (TBB != Tail) {
477     RemovedBlocks.push_back(TBB);
478     TBB->eraseFromParent();
479   }
480   if (FBB != Tail) {
481     RemovedBlocks.push_back(FBB);
482     FBB->eraseFromParent();
483   }
484
485   assert(Head->succ_empty() && "Additional head successors?");
486   if (Head->isLayoutSuccessor(Tail)) {
487     // Splice Tail onto the end of Head.
488     DEBUG(dbgs() << "Joining tail BB#" << Tail->getNumber()
489                  << " into head BB#" << Head->getNumber() << '\n');
490     Head->splice(Head->end(), Tail,
491                      Tail->begin(), Tail->end());
492     Head->transferSuccessorsAndUpdatePHIs(Tail);
493     RemovedBlocks.push_back(Tail);
494     Tail->eraseFromParent();
495   } else {
496     // We need a branch to Tail, let code placement work it out later.
497     DEBUG(dbgs() << "Converting to unconditional branch.\n");
498     SmallVector<MachineOperand, 0> EmptyCond;
499     TII->InsertBranch(*Head, Tail, 0, EmptyCond, HeadDL);
500     Head->addSuccessor(Tail);
501   }
502   DEBUG(dbgs() << *Head);
503 }
504
505
506 //===----------------------------------------------------------------------===//
507 //                           EarlyIfConverter Pass
508 //===----------------------------------------------------------------------===//
509
510 namespace {
511 class EarlyIfConverter : public MachineFunctionPass {
512   const TargetInstrInfo *TII;
513   const TargetRegisterInfo *TRI;
514   MachineRegisterInfo *MRI;
515   MachineDominatorTree *DomTree;
516   SSAIfConv IfConv;
517
518 public:
519   static char ID;
520   EarlyIfConverter() : MachineFunctionPass(ID) {}
521   void getAnalysisUsage(AnalysisUsage &AU) const;
522   bool runOnMachineFunction(MachineFunction &MF);
523
524 private:
525   bool tryConvertIf(MachineBasicBlock*);
526   void updateDomTree(ArrayRef<MachineBasicBlock*> Removed);
527 };
528 } // end anonymous namespace
529
530 char EarlyIfConverter::ID = 0;
531 char &llvm::EarlyIfConverterID = EarlyIfConverter::ID;
532
533 INITIALIZE_PASS_BEGIN(EarlyIfConverter,
534                       "early-ifcvt", "Early If Converter", false, false)
535 INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo)
536 INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
537 INITIALIZE_PASS_END(EarlyIfConverter,
538                       "early-ifcvt", "Early If Converter", false, false)
539
540 void EarlyIfConverter::getAnalysisUsage(AnalysisUsage &AU) const {
541   AU.addRequired<MachineBranchProbabilityInfo>();
542   AU.addRequired<MachineDominatorTree>();
543   AU.addPreserved<MachineDominatorTree>();
544   MachineFunctionPass::getAnalysisUsage(AU);
545 }
546
547 /// Update the dominator tree after if-conversion erased some blocks.
548 void EarlyIfConverter::updateDomTree(ArrayRef<MachineBasicBlock*> Removed) {
549   // convertIf can remove TBB, FBB, and Tail can be merged into Head.
550   // TBB and FBB should not dominate any blocks.
551   // Tail children should be transferred to Head.
552   MachineDomTreeNode *HeadNode = DomTree->getNode(IfConv.Head);
553   for (unsigned i = 0, e = Removed.size(); i != e; ++i) {
554     MachineDomTreeNode *Node = DomTree->getNode(Removed[i]);
555     assert(Node != HeadNode && "Cannot erase the head node");
556     while (Node->getNumChildren()) {
557       assert(Node->getBlock() == IfConv.Tail && "Unexpected children");
558       DomTree->changeImmediateDominator(Node->getChildren().back(), HeadNode);
559     }
560     DomTree->eraseNode(Removed[i]);
561   }
562 }
563
564 /// Attempt repeated if-conversion on MBB, return true if successful.
565 ///
566 bool EarlyIfConverter::tryConvertIf(MachineBasicBlock *MBB) {
567   bool Changed = false;
568   while (IfConv.canConvertIf(MBB)) {
569     // If-convert MBB and update analyses.
570     SmallVector<MachineBasicBlock*, 4> RemovedBlocks;
571     IfConv.convertIf(RemovedBlocks);
572     Changed = true;
573     updateDomTree(RemovedBlocks);
574   }
575   return Changed;
576 }
577
578 bool EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) {
579   DEBUG(dbgs() << "********** EARLY IF-CONVERSION **********\n"
580                << "********** Function: "
581                << ((Value*)MF.getFunction())->getName() << '\n');
582   TII = MF.getTarget().getInstrInfo();
583   TRI = MF.getTarget().getRegisterInfo();
584   MRI = &MF.getRegInfo();
585   DomTree = &getAnalysis<MachineDominatorTree>();
586
587   bool Changed = false;
588   IfConv.runOnMachineFunction(MF);
589
590   // Visit blocks in dominator tree post-order. The post-order enables nested
591   // if-conversion in a single pass. The tryConvertIf() function may erase
592   // blocks, but only blocks dominated by the head block. This makes it safe to
593   // update the dominator tree while the post-order iterator is still active.
594   for (po_iterator<MachineDominatorTree*>
595        I = po_begin(DomTree), E = po_end(DomTree); I != E; ++I)
596     if (tryConvertIf(I->getBlock()))
597       Changed = true;
598
599   MF.verify(this, "After early if-conversion");
600   return Changed;
601 }