EarlyIfConversion.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. //===-- EarlyIfConversion.cpp - If-conversion on SSA form machine code ----===//
  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. // Early if-conversion is for out-of-order CPUs that don't have a lot of
  10. // predicable instructions. The goal is to eliminate conditional branches that
  11. // may mispredict.
  12. //
  13. // Instructions from both sides of the branch are executed specutatively, and a
  14. // cmov instruction selects the result.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #include "llvm/ADT/BitVector.h"
  18. #include "llvm/ADT/PostOrderIterator.h"
  19. #include "llvm/ADT/SetVector.h"
  20. #include "llvm/ADT/SmallPtrSet.h"
  21. #include "llvm/ADT/SparseSet.h"
  22. #include "llvm/ADT/Statistic.h"
  23. #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
  24. #include "llvm/CodeGen/MachineDominators.h"
  25. #include "llvm/CodeGen/MachineFunction.h"
  26. #include "llvm/CodeGen/MachineFunctionPass.h"
  27. #include "llvm/CodeGen/MachineInstr.h"
  28. #include "llvm/CodeGen/MachineLoopInfo.h"
  29. #include "llvm/CodeGen/MachineRegisterInfo.h"
  30. #include "llvm/CodeGen/MachineTraceMetrics.h"
  31. #include "llvm/CodeGen/Passes.h"
  32. #include "llvm/CodeGen/TargetInstrInfo.h"
  33. #include "llvm/CodeGen/TargetRegisterInfo.h"
  34. #include "llvm/CodeGen/TargetSubtargetInfo.h"
  35. #include "llvm/Support/CommandLine.h"
  36. #include "llvm/Support/Debug.h"
  37. #include "llvm/Support/raw_ostream.h"
  38. using namespace llvm;
  39. #define DEBUG_TYPE "early-ifcvt"
  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. // Stress testing mode - disable heuristics.
  46. static cl::opt<bool> Stress("stress-early-ifcvt", cl::Hidden,
  47. cl::desc("Turn all knobs to 11"));
  48. STATISTIC(NumDiamondsSeen, "Number of diamonds");
  49. STATISTIC(NumDiamondsConv, "Number of diamonds converted");
  50. STATISTIC(NumTrianglesSeen, "Number of triangles");
  51. STATISTIC(NumTrianglesConv, "Number of triangles converted");
  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. public:
  79. /// The block containing the conditional branch.
  80. MachineBasicBlock *Head;
  81. /// The block containing phis after the if-then-else.
  82. MachineBasicBlock *Tail;
  83. /// The 'true' conditional block as determined by AnalyzeBranch.
  84. MachineBasicBlock *TBB;
  85. /// The 'false' conditional block as determined by AnalyzeBranch.
  86. MachineBasicBlock *FBB;
  87. /// isTriangle - When there is no 'else' block, either TBB or FBB will be
  88. /// equal to Tail.
  89. bool isTriangle() const { return TBB == Tail || FBB == Tail; }
  90. /// Returns the Tail predecessor for the True side.
  91. MachineBasicBlock *getTPred() const { return TBB == Tail ? Head : TBB; }
  92. /// Returns the Tail predecessor for the False side.
  93. MachineBasicBlock *getFPred() const { return FBB == Tail ? Head : FBB; }
  94. /// Information about each phi in the Tail block.
  95. struct PHIInfo {
  96. MachineInstr *PHI;
  97. unsigned TReg, FReg;
  98. // Latencies from Cond+Branch, TReg, and FReg to DstReg.
  99. int CondCycles, TCycles, FCycles;
  100. PHIInfo(MachineInstr *phi)
  101. : PHI(phi), TReg(0), FReg(0), CondCycles(0), TCycles(0), FCycles(0) {}
  102. };
  103. SmallVector<PHIInfo, 8> PHIs;
  104. private:
  105. /// The branch condition determined by AnalyzeBranch.
  106. SmallVector<MachineOperand, 4> Cond;
  107. /// Instructions in Head that define values used by the conditional blocks.
  108. /// The hoisted instructions must be inserted after these instructions.
  109. SmallPtrSet<MachineInstr*, 8> InsertAfter;
  110. /// Register units clobbered by the conditional blocks.
  111. BitVector ClobberedRegUnits;
  112. // Scratch pad for findInsertionPoint.
  113. SparseSet<unsigned> LiveRegUnits;
  114. /// Insertion point in Head for speculatively executed instructions form TBB
  115. /// and FBB.
  116. MachineBasicBlock::iterator InsertionPoint;
  117. /// Return true if all non-terminator instructions in MBB can be safely
  118. /// speculated.
  119. bool canSpeculateInstrs(MachineBasicBlock *MBB);
  120. /// Return true if all non-terminator instructions in MBB can be safely
  121. /// predicated.
  122. bool canPredicateInstrs(MachineBasicBlock *MBB);
  123. /// Scan through instruction dependencies and update InsertAfter array.
  124. /// Return false if any dependency is incompatible with if conversion.
  125. bool InstrDependenciesAllowIfConv(MachineInstr *I);
  126. /// Predicate all instructions of the basic block with current condition
  127. /// except for terminators. Reverse the condition if ReversePredicate is set.
  128. void PredicateBlock(MachineBasicBlock *MBB, bool ReversePredicate);
  129. /// Find a valid insertion point in Head.
  130. bool findInsertionPoint();
  131. /// Replace PHI instructions in Tail with selects.
  132. void replacePHIInstrs();
  133. /// Insert selects and rewrite PHI operands to use them.
  134. void rewritePHIOperands();
  135. public:
  136. /// runOnMachineFunction - Initialize per-function data structures.
  137. void runOnMachineFunction(MachineFunction &MF) {
  138. TII = MF.getSubtarget().getInstrInfo();
  139. TRI = MF.getSubtarget().getRegisterInfo();
  140. MRI = &MF.getRegInfo();
  141. LiveRegUnits.clear();
  142. LiveRegUnits.setUniverse(TRI->getNumRegUnits());
  143. ClobberedRegUnits.clear();
  144. ClobberedRegUnits.resize(TRI->getNumRegUnits());
  145. }
  146. /// canConvertIf - If the sub-CFG headed by MBB can be if-converted,
  147. /// initialize the internal state, and return true.
  148. /// If predicate is set try to predicate the block otherwise try to
  149. /// speculatively execute it.
  150. bool canConvertIf(MachineBasicBlock *MBB, bool Predicate = false);
  151. /// convertIf - If-convert the last block passed to canConvertIf(), assuming
  152. /// it is possible. Add any erased blocks to RemovedBlocks.
  153. void convertIf(SmallVectorImpl<MachineBasicBlock *> &RemovedBlocks,
  154. bool Predicate = false);
  155. };
  156. } // end anonymous namespace
  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. LLVM_DEBUG(dbgs() << printMBBReference(*MBB) << " has live-ins.\n");
  170. return false;
  171. }
  172. unsigned InstrCount = 0;
  173. // Check all instructions, except the terminators. It is assumed that
  174. // terminators never have side effects or define any used register values.
  175. for (MachineBasicBlock::iterator I = MBB->begin(),
  176. E = MBB->getFirstTerminator(); I != E; ++I) {
  177. if (I->isDebugInstr())
  178. continue;
  179. if (++InstrCount > BlockInstrLimit && !Stress) {
  180. LLVM_DEBUG(dbgs() << printMBBReference(*MBB) << " has more than "
  181. << BlockInstrLimit << " instructions.\n");
  182. return false;
  183. }
  184. // There shouldn't normally be any phis in a single-predecessor block.
  185. if (I->isPHI()) {
  186. LLVM_DEBUG(dbgs() << "Can't hoist: " << *I);
  187. return false;
  188. }
  189. // Don't speculate loads. Note that it may be possible and desirable to
  190. // speculate GOT or constant pool loads that are guaranteed not to trap,
  191. // but we don't support that for now.
  192. if (I->mayLoad()) {
  193. LLVM_DEBUG(dbgs() << "Won't speculate load: " << *I);
  194. return false;
  195. }
  196. // We never speculate stores, so an AA pointer isn't necessary.
  197. bool DontMoveAcrossStore = true;
  198. if (!I->isSafeToMove(nullptr, DontMoveAcrossStore)) {
  199. LLVM_DEBUG(dbgs() << "Can't speculate: " << *I);
  200. return false;
  201. }
  202. // Check for any dependencies on Head instructions.
  203. if (!InstrDependenciesAllowIfConv(&(*I)))
  204. return false;
  205. }
  206. return true;
  207. }
  208. /// Check that there is no dependencies preventing if conversion.
  209. ///
  210. /// If instruction uses any values that are defined in the head basic block,
  211. /// the defining instructions are added to InsertAfter.
  212. bool SSAIfConv::InstrDependenciesAllowIfConv(MachineInstr *I) {
  213. for (const MachineOperand &MO : I->operands()) {
  214. if (MO.isRegMask()) {
  215. LLVM_DEBUG(dbgs() << "Won't speculate regmask: " << *I);
  216. return false;
  217. }
  218. if (!MO.isReg())
  219. continue;
  220. Register Reg = MO.getReg();
  221. // Remember clobbered regunits.
  222. if (MO.isDef() && Register::isPhysicalRegister(Reg))
  223. for (MCRegUnitIterator Units(Reg, TRI); Units.isValid(); ++Units)
  224. ClobberedRegUnits.set(*Units);
  225. if (!MO.readsReg() || !Register::isVirtualRegister(Reg))
  226. continue;
  227. MachineInstr *DefMI = MRI->getVRegDef(Reg);
  228. if (!DefMI || DefMI->getParent() != Head)
  229. continue;
  230. if (InsertAfter.insert(DefMI).second)
  231. LLVM_DEBUG(dbgs() << printMBBReference(*I->getParent()) << " depends on "
  232. << *DefMI);
  233. if (DefMI->isTerminator()) {
  234. LLVM_DEBUG(dbgs() << "Can't insert instructions below terminator.\n");
  235. return false;
  236. }
  237. }
  238. return true;
  239. }
  240. /// canPredicateInstrs - Returns true if all the instructions in MBB can safely
  241. /// be predicates. The terminators are not considered.
  242. ///
  243. /// If instructions use any values that are defined in the head basic block,
  244. /// the defining instructions are added to InsertAfter.
  245. ///
  246. /// Any clobbered regunits are added to ClobberedRegUnits.
  247. ///
  248. bool SSAIfConv::canPredicateInstrs(MachineBasicBlock *MBB) {
  249. // Reject any live-in physregs. It's probably CPSR/EFLAGS, and very hard to
  250. // get right.
  251. if (!MBB->livein_empty()) {
  252. LLVM_DEBUG(dbgs() << printMBBReference(*MBB) << " has live-ins.\n");
  253. return false;
  254. }
  255. unsigned InstrCount = 0;
  256. // Check all instructions, except the terminators. It is assumed that
  257. // terminators never have side effects or define any used register values.
  258. for (MachineBasicBlock::iterator I = MBB->begin(),
  259. E = MBB->getFirstTerminator();
  260. I != E; ++I) {
  261. if (I->isDebugInstr())
  262. continue;
  263. if (++InstrCount > BlockInstrLimit && !Stress) {
  264. LLVM_DEBUG(dbgs() << printMBBReference(*MBB) << " has more than "
  265. << BlockInstrLimit << " instructions.\n");
  266. return false;
  267. }
  268. // There shouldn't normally be any phis in a single-predecessor block.
  269. if (I->isPHI()) {
  270. LLVM_DEBUG(dbgs() << "Can't predicate: " << *I);
  271. return false;
  272. }
  273. // Check that instruction is predicable and that it is not already
  274. // predicated.
  275. if (!TII->isPredicable(*I) || TII->isPredicated(*I)) {
  276. return false;
  277. }
  278. // Check for any dependencies on Head instructions.
  279. if (!InstrDependenciesAllowIfConv(&(*I)))
  280. return false;
  281. }
  282. return true;
  283. }
  284. // Apply predicate to all instructions in the machine block.
  285. void SSAIfConv::PredicateBlock(MachineBasicBlock *MBB, bool ReversePredicate) {
  286. auto Condition = Cond;
  287. if (ReversePredicate)
  288. TII->reverseBranchCondition(Condition);
  289. // Terminators don't need to be predicated as they will be removed.
  290. for (MachineBasicBlock::iterator I = MBB->begin(),
  291. E = MBB->getFirstTerminator();
  292. I != E; ++I) {
  293. if (I->isDebugInstr())
  294. continue;
  295. TII->PredicateInstruction(*I, Condition);
  296. }
  297. }
  298. /// Find an insertion point in Head for the speculated instructions. The
  299. /// insertion point must be:
  300. ///
  301. /// 1. Before any terminators.
  302. /// 2. After any instructions in InsertAfter.
  303. /// 3. Not have any clobbered regunits live.
  304. ///
  305. /// This function sets InsertionPoint and returns true when successful, it
  306. /// returns false if no valid insertion point could be found.
  307. ///
  308. bool SSAIfConv::findInsertionPoint() {
  309. // Keep track of live regunits before the current position.
  310. // Only track RegUnits that are also in ClobberedRegUnits.
  311. LiveRegUnits.clear();
  312. SmallVector<unsigned, 8> Reads;
  313. MachineBasicBlock::iterator FirstTerm = Head->getFirstTerminator();
  314. MachineBasicBlock::iterator I = Head->end();
  315. MachineBasicBlock::iterator B = Head->begin();
  316. while (I != B) {
  317. --I;
  318. // Some of the conditional code depends in I.
  319. if (InsertAfter.count(&*I)) {
  320. LLVM_DEBUG(dbgs() << "Can't insert code after " << *I);
  321. return false;
  322. }
  323. // Update live regunits.
  324. for (const MachineOperand &MO : I->operands()) {
  325. // We're ignoring regmask operands. That is conservatively correct.
  326. if (!MO.isReg())
  327. continue;
  328. Register Reg = MO.getReg();
  329. if (!Register::isPhysicalRegister(Reg))
  330. continue;
  331. // I clobbers Reg, so it isn't live before I.
  332. if (MO.isDef())
  333. for (MCRegUnitIterator Units(Reg, TRI); Units.isValid(); ++Units)
  334. LiveRegUnits.erase(*Units);
  335. // Unless I reads Reg.
  336. if (MO.readsReg())
  337. Reads.push_back(Reg);
  338. }
  339. // Anything read by I is live before I.
  340. while (!Reads.empty())
  341. for (MCRegUnitIterator Units(Reads.pop_back_val(), TRI); Units.isValid();
  342. ++Units)
  343. if (ClobberedRegUnits.test(*Units))
  344. LiveRegUnits.insert(*Units);
  345. // We can't insert before a terminator.
  346. if (I != FirstTerm && I->isTerminator())
  347. continue;
  348. // Some of the clobbered registers are live before I, not a valid insertion
  349. // point.
  350. if (!LiveRegUnits.empty()) {
  351. LLVM_DEBUG({
  352. dbgs() << "Would clobber";
  353. for (SparseSet<unsigned>::const_iterator
  354. i = LiveRegUnits.begin(), e = LiveRegUnits.end(); i != e; ++i)
  355. dbgs() << ' ' << printRegUnit(*i, TRI);
  356. dbgs() << " live before " << *I;
  357. });
  358. continue;
  359. }
  360. // This is a valid insertion point.
  361. InsertionPoint = I;
  362. LLVM_DEBUG(dbgs() << "Can insert before " << *I);
  363. return true;
  364. }
  365. LLVM_DEBUG(dbgs() << "No legal insertion point found.\n");
  366. return false;
  367. }
  368. /// canConvertIf - analyze the sub-cfg rooted in MBB, and return true if it is
  369. /// a potential candidate for if-conversion. Fill out the internal state.
  370. ///
  371. bool SSAIfConv::canConvertIf(MachineBasicBlock *MBB, bool Predicate) {
  372. Head = MBB;
  373. TBB = FBB = Tail = nullptr;
  374. if (Head->succ_size() != 2)
  375. return false;
  376. MachineBasicBlock *Succ0 = Head->succ_begin()[0];
  377. MachineBasicBlock *Succ1 = Head->succ_begin()[1];
  378. // Canonicalize so Succ0 has MBB as its single predecessor.
  379. if (Succ0->pred_size() != 1)
  380. std::swap(Succ0, Succ1);
  381. if (Succ0->pred_size() != 1 || Succ0->succ_size() != 1)
  382. return false;
  383. Tail = Succ0->succ_begin()[0];
  384. // This is not a triangle.
  385. if (Tail != Succ1) {
  386. // Check for a diamond. We won't deal with any critical edges.
  387. if (Succ1->pred_size() != 1 || Succ1->succ_size() != 1 ||
  388. Succ1->succ_begin()[0] != Tail)
  389. return false;
  390. LLVM_DEBUG(dbgs() << "\nDiamond: " << printMBBReference(*Head) << " -> "
  391. << printMBBReference(*Succ0) << "/"
  392. << printMBBReference(*Succ1) << " -> "
  393. << printMBBReference(*Tail) << '\n');
  394. // Live-in physregs are tricky to get right when speculating code.
  395. if (!Tail->livein_empty()) {
  396. LLVM_DEBUG(dbgs() << "Tail has live-ins.\n");
  397. return false;
  398. }
  399. } else {
  400. LLVM_DEBUG(dbgs() << "\nTriangle: " << printMBBReference(*Head) << " -> "
  401. << printMBBReference(*Succ0) << " -> "
  402. << printMBBReference(*Tail) << '\n');
  403. }
  404. // This is a triangle or a diamond.
  405. // Skip if we cannot predicate and there are no phis skip as there must be
  406. // side effects that can only be handled with predication.
  407. if (!Predicate && (Tail->empty() || !Tail->front().isPHI())) {
  408. LLVM_DEBUG(dbgs() << "No phis in tail.\n");
  409. return false;
  410. }
  411. // The branch we're looking to eliminate must be analyzable.
  412. Cond.clear();
  413. if (TII->analyzeBranch(*Head, TBB, FBB, Cond)) {
  414. LLVM_DEBUG(dbgs() << "Branch not analyzable.\n");
  415. return false;
  416. }
  417. // This is weird, probably some sort of degenerate CFG.
  418. if (!TBB) {
  419. LLVM_DEBUG(dbgs() << "AnalyzeBranch didn't find conditional branch.\n");
  420. return false;
  421. }
  422. // Make sure the analyzed branch is conditional; one of the successors
  423. // could be a landing pad. (Empty landing pads can be generated on Windows.)
  424. if (Cond.empty()) {
  425. LLVM_DEBUG(dbgs() << "AnalyzeBranch found an unconditional branch.\n");
  426. return false;
  427. }
  428. // AnalyzeBranch doesn't set FBB on a fall-through branch.
  429. // Make sure it is always set.
  430. FBB = TBB == Succ0 ? Succ1 : Succ0;
  431. // Any phis in the tail block must be convertible to selects.
  432. PHIs.clear();
  433. MachineBasicBlock *TPred = getTPred();
  434. MachineBasicBlock *FPred = getFPred();
  435. for (MachineBasicBlock::iterator I = Tail->begin(), E = Tail->end();
  436. I != E && I->isPHI(); ++I) {
  437. PHIs.push_back(&*I);
  438. PHIInfo &PI = PHIs.back();
  439. // Find PHI operands corresponding to TPred and FPred.
  440. for (unsigned i = 1; i != PI.PHI->getNumOperands(); i += 2) {
  441. if (PI.PHI->getOperand(i+1).getMBB() == TPred)
  442. PI.TReg = PI.PHI->getOperand(i).getReg();
  443. if (PI.PHI->getOperand(i+1).getMBB() == FPred)
  444. PI.FReg = PI.PHI->getOperand(i).getReg();
  445. }
  446. assert(Register::isVirtualRegister(PI.TReg) && "Bad PHI");
  447. assert(Register::isVirtualRegister(PI.FReg) && "Bad PHI");
  448. // Get target information.
  449. if (!TII->canInsertSelect(*Head, Cond, PI.TReg, PI.FReg,
  450. PI.CondCycles, PI.TCycles, PI.FCycles)) {
  451. LLVM_DEBUG(dbgs() << "Can't convert: " << *PI.PHI);
  452. return false;
  453. }
  454. }
  455. // Check that the conditional instructions can be speculated.
  456. InsertAfter.clear();
  457. ClobberedRegUnits.reset();
  458. if (Predicate) {
  459. if (TBB != Tail && !canPredicateInstrs(TBB))
  460. return false;
  461. if (FBB != Tail && !canPredicateInstrs(FBB))
  462. return false;
  463. } else {
  464. if (TBB != Tail && !canSpeculateInstrs(TBB))
  465. return false;
  466. if (FBB != Tail && !canSpeculateInstrs(FBB))
  467. return false;
  468. }
  469. // Try to find a valid insertion point for the speculated instructions in the
  470. // head basic block.
  471. if (!findInsertionPoint())
  472. return false;
  473. if (isTriangle())
  474. ++NumTrianglesSeen;
  475. else
  476. ++NumDiamondsSeen;
  477. return true;
  478. }
  479. /// replacePHIInstrs - Completely replace PHI instructions with selects.
  480. /// This is possible when the only Tail predecessors are the if-converted
  481. /// blocks.
  482. void SSAIfConv::replacePHIInstrs() {
  483. assert(Tail->pred_size() == 2 && "Cannot replace PHIs");
  484. MachineBasicBlock::iterator FirstTerm = Head->getFirstTerminator();
  485. assert(FirstTerm != Head->end() && "No terminators");
  486. DebugLoc HeadDL = FirstTerm->getDebugLoc();
  487. // Convert all PHIs to select instructions inserted before FirstTerm.
  488. for (unsigned i = 0, e = PHIs.size(); i != e; ++i) {
  489. PHIInfo &PI = PHIs[i];
  490. LLVM_DEBUG(dbgs() << "If-converting " << *PI.PHI);
  491. Register DstReg = PI.PHI->getOperand(0).getReg();
  492. TII->insertSelect(*Head, FirstTerm, HeadDL, DstReg, Cond, PI.TReg, PI.FReg);
  493. LLVM_DEBUG(dbgs() << " --> " << *std::prev(FirstTerm));
  494. PI.PHI->eraseFromParent();
  495. PI.PHI = nullptr;
  496. }
  497. }
  498. /// rewritePHIOperands - When there are additional Tail predecessors, insert
  499. /// select instructions in Head and rewrite PHI operands to use the selects.
  500. /// Keep the PHI instructions in Tail to handle the other predecessors.
  501. void SSAIfConv::rewritePHIOperands() {
  502. MachineBasicBlock::iterator FirstTerm = Head->getFirstTerminator();
  503. assert(FirstTerm != Head->end() && "No terminators");
  504. DebugLoc HeadDL = FirstTerm->getDebugLoc();
  505. // Convert all PHIs to select instructions inserted before FirstTerm.
  506. for (unsigned i = 0, e = PHIs.size(); i != e; ++i) {
  507. PHIInfo &PI = PHIs[i];
  508. unsigned DstReg = 0;
  509. LLVM_DEBUG(dbgs() << "If-converting " << *PI.PHI);
  510. if (PI.TReg == PI.FReg) {
  511. // We do not need the select instruction if both incoming values are
  512. // equal.
  513. DstReg = PI.TReg;
  514. } else {
  515. Register PHIDst = PI.PHI->getOperand(0).getReg();
  516. DstReg = MRI->createVirtualRegister(MRI->getRegClass(PHIDst));
  517. TII->insertSelect(*Head, FirstTerm, HeadDL,
  518. DstReg, Cond, PI.TReg, PI.FReg);
  519. LLVM_DEBUG(dbgs() << " --> " << *std::prev(FirstTerm));
  520. }
  521. // Rewrite PHI operands TPred -> (DstReg, Head), remove FPred.
  522. for (unsigned i = PI.PHI->getNumOperands(); i != 1; i -= 2) {
  523. MachineBasicBlock *MBB = PI.PHI->getOperand(i-1).getMBB();
  524. if (MBB == getTPred()) {
  525. PI.PHI->getOperand(i-1).setMBB(Head);
  526. PI.PHI->getOperand(i-2).setReg(DstReg);
  527. } else if (MBB == getFPred()) {
  528. PI.PHI->RemoveOperand(i-1);
  529. PI.PHI->RemoveOperand(i-2);
  530. }
  531. }
  532. LLVM_DEBUG(dbgs() << " --> " << *PI.PHI);
  533. }
  534. }
  535. /// convertIf - Execute the if conversion after canConvertIf has determined the
  536. /// feasibility.
  537. ///
  538. /// Any basic blocks erased will be added to RemovedBlocks.
  539. ///
  540. void SSAIfConv::convertIf(SmallVectorImpl<MachineBasicBlock *> &RemovedBlocks,
  541. bool Predicate) {
  542. assert(Head && Tail && TBB && FBB && "Call canConvertIf first.");
  543. // Update statistics.
  544. if (isTriangle())
  545. ++NumTrianglesConv;
  546. else
  547. ++NumDiamondsConv;
  548. // Move all instructions into Head, except for the terminators.
  549. if (TBB != Tail) {
  550. if (Predicate)
  551. PredicateBlock(TBB, /*ReversePredicate=*/false);
  552. Head->splice(InsertionPoint, TBB, TBB->begin(), TBB->getFirstTerminator());
  553. }
  554. if (FBB != Tail) {
  555. if (Predicate)
  556. PredicateBlock(FBB, /*ReversePredicate=*/true);
  557. Head->splice(InsertionPoint, FBB, FBB->begin(), FBB->getFirstTerminator());
  558. }
  559. // Are there extra Tail predecessors?
  560. bool ExtraPreds = Tail->pred_size() != 2;
  561. if (ExtraPreds)
  562. rewritePHIOperands();
  563. else
  564. replacePHIInstrs();
  565. // Fix up the CFG, temporarily leave Head without any successors.
  566. Head->removeSuccessor(TBB);
  567. Head->removeSuccessor(FBB, true);
  568. if (TBB != Tail)
  569. TBB->removeSuccessor(Tail, true);
  570. if (FBB != Tail)
  571. FBB->removeSuccessor(Tail, true);
  572. // Fix up Head's terminators.
  573. // It should become a single branch or a fallthrough.
  574. DebugLoc HeadDL = Head->getFirstTerminator()->getDebugLoc();
  575. TII->removeBranch(*Head);
  576. // Erase the now empty conditional blocks. It is likely that Head can fall
  577. // through to Tail, and we can join the two blocks.
  578. if (TBB != Tail) {
  579. RemovedBlocks.push_back(TBB);
  580. TBB->eraseFromParent();
  581. }
  582. if (FBB != Tail) {
  583. RemovedBlocks.push_back(FBB);
  584. FBB->eraseFromParent();
  585. }
  586. assert(Head->succ_empty() && "Additional head successors?");
  587. if (!ExtraPreds && Head->isLayoutSuccessor(Tail)) {
  588. // Splice Tail onto the end of Head.
  589. LLVM_DEBUG(dbgs() << "Joining tail " << printMBBReference(*Tail)
  590. << " into head " << printMBBReference(*Head) << '\n');
  591. Head->splice(Head->end(), Tail,
  592. Tail->begin(), Tail->end());
  593. Head->transferSuccessorsAndUpdatePHIs(Tail);
  594. RemovedBlocks.push_back(Tail);
  595. Tail->eraseFromParent();
  596. } else {
  597. // We need a branch to Tail, let code placement work it out later.
  598. LLVM_DEBUG(dbgs() << "Converting to unconditional branch.\n");
  599. SmallVector<MachineOperand, 0> EmptyCond;
  600. TII->insertBranch(*Head, Tail, nullptr, EmptyCond, HeadDL);
  601. Head->addSuccessor(Tail);
  602. }
  603. LLVM_DEBUG(dbgs() << *Head);
  604. }
  605. //===----------------------------------------------------------------------===//
  606. // EarlyIfConverter Pass
  607. //===----------------------------------------------------------------------===//
  608. namespace {
  609. class EarlyIfConverter : public MachineFunctionPass {
  610. const TargetInstrInfo *TII;
  611. const TargetRegisterInfo *TRI;
  612. MCSchedModel SchedModel;
  613. MachineRegisterInfo *MRI;
  614. MachineDominatorTree *DomTree;
  615. MachineLoopInfo *Loops;
  616. MachineTraceMetrics *Traces;
  617. MachineTraceMetrics::Ensemble *MinInstr;
  618. SSAIfConv IfConv;
  619. public:
  620. static char ID;
  621. EarlyIfConverter() : MachineFunctionPass(ID) {}
  622. void getAnalysisUsage(AnalysisUsage &AU) const override;
  623. bool runOnMachineFunction(MachineFunction &MF) override;
  624. StringRef getPassName() const override { return "Early If-Conversion"; }
  625. private:
  626. bool tryConvertIf(MachineBasicBlock*);
  627. void invalidateTraces();
  628. bool shouldConvertIf();
  629. };
  630. } // end anonymous namespace
  631. char EarlyIfConverter::ID = 0;
  632. char &llvm::EarlyIfConverterID = EarlyIfConverter::ID;
  633. INITIALIZE_PASS_BEGIN(EarlyIfConverter, DEBUG_TYPE,
  634. "Early If Converter", false, false)
  635. INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo)
  636. INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
  637. INITIALIZE_PASS_DEPENDENCY(MachineTraceMetrics)
  638. INITIALIZE_PASS_END(EarlyIfConverter, DEBUG_TYPE,
  639. "Early If Converter", false, false)
  640. void EarlyIfConverter::getAnalysisUsage(AnalysisUsage &AU) const {
  641. AU.addRequired<MachineBranchProbabilityInfo>();
  642. AU.addRequired<MachineDominatorTree>();
  643. AU.addPreserved<MachineDominatorTree>();
  644. AU.addRequired<MachineLoopInfo>();
  645. AU.addPreserved<MachineLoopInfo>();
  646. AU.addRequired<MachineTraceMetrics>();
  647. AU.addPreserved<MachineTraceMetrics>();
  648. MachineFunctionPass::getAnalysisUsage(AU);
  649. }
  650. namespace {
  651. /// Update the dominator tree after if-conversion erased some blocks.
  652. void updateDomTree(MachineDominatorTree *DomTree, const SSAIfConv &IfConv,
  653. ArrayRef<MachineBasicBlock *> Removed) {
  654. // convertIf can remove TBB, FBB, and Tail can be merged into Head.
  655. // TBB and FBB should not dominate any blocks.
  656. // Tail children should be transferred to Head.
  657. MachineDomTreeNode *HeadNode = DomTree->getNode(IfConv.Head);
  658. for (auto B : Removed) {
  659. MachineDomTreeNode *Node = DomTree->getNode(B);
  660. assert(Node != HeadNode && "Cannot erase the head node");
  661. while (Node->getNumChildren()) {
  662. assert(Node->getBlock() == IfConv.Tail && "Unexpected children");
  663. DomTree->changeImmediateDominator(Node->getChildren().back(), HeadNode);
  664. }
  665. DomTree->eraseNode(B);
  666. }
  667. }
  668. /// Update LoopInfo after if-conversion.
  669. void updateLoops(MachineLoopInfo *Loops,
  670. ArrayRef<MachineBasicBlock *> Removed) {
  671. if (!Loops)
  672. return;
  673. // If-conversion doesn't change loop structure, and it doesn't mess with back
  674. // edges, so updating LoopInfo is simply removing the dead blocks.
  675. for (auto B : Removed)
  676. Loops->removeBlock(B);
  677. }
  678. } // namespace
  679. /// Invalidate MachineTraceMetrics before if-conversion.
  680. void EarlyIfConverter::invalidateTraces() {
  681. Traces->verifyAnalysis();
  682. Traces->invalidate(IfConv.Head);
  683. Traces->invalidate(IfConv.Tail);
  684. Traces->invalidate(IfConv.TBB);
  685. Traces->invalidate(IfConv.FBB);
  686. Traces->verifyAnalysis();
  687. }
  688. // Adjust cycles with downward saturation.
  689. static unsigned adjCycles(unsigned Cyc, int Delta) {
  690. if (Delta < 0 && Cyc + Delta > Cyc)
  691. return 0;
  692. return Cyc + Delta;
  693. }
  694. /// Apply cost model and heuristics to the if-conversion in IfConv.
  695. /// Return true if the conversion is a good idea.
  696. ///
  697. bool EarlyIfConverter::shouldConvertIf() {
  698. // Stress testing mode disables all cost considerations.
  699. if (Stress)
  700. return true;
  701. if (!MinInstr)
  702. MinInstr = Traces->getEnsemble(MachineTraceMetrics::TS_MinInstrCount);
  703. MachineTraceMetrics::Trace TBBTrace = MinInstr->getTrace(IfConv.getTPred());
  704. MachineTraceMetrics::Trace FBBTrace = MinInstr->getTrace(IfConv.getFPred());
  705. LLVM_DEBUG(dbgs() << "TBB: " << TBBTrace << "FBB: " << FBBTrace);
  706. unsigned MinCrit = std::min(TBBTrace.getCriticalPath(),
  707. FBBTrace.getCriticalPath());
  708. // Set a somewhat arbitrary limit on the critical path extension we accept.
  709. unsigned CritLimit = SchedModel.MispredictPenalty/2;
  710. // If-conversion only makes sense when there is unexploited ILP. Compute the
  711. // maximum-ILP resource length of the trace after if-conversion. Compare it
  712. // to the shortest critical path.
  713. SmallVector<const MachineBasicBlock*, 1> ExtraBlocks;
  714. if (IfConv.TBB != IfConv.Tail)
  715. ExtraBlocks.push_back(IfConv.TBB);
  716. unsigned ResLength = FBBTrace.getResourceLength(ExtraBlocks);
  717. LLVM_DEBUG(dbgs() << "Resource length " << ResLength
  718. << ", minimal critical path " << MinCrit << '\n');
  719. if (ResLength > MinCrit + CritLimit) {
  720. LLVM_DEBUG(dbgs() << "Not enough available ILP.\n");
  721. return false;
  722. }
  723. // Assume that the depth of the first head terminator will also be the depth
  724. // of the select instruction inserted, as determined by the flag dependency.
  725. // TBB / FBB data dependencies may delay the select even more.
  726. MachineTraceMetrics::Trace HeadTrace = MinInstr->getTrace(IfConv.Head);
  727. unsigned BranchDepth =
  728. HeadTrace.getInstrCycles(*IfConv.Head->getFirstTerminator()).Depth;
  729. LLVM_DEBUG(dbgs() << "Branch depth: " << BranchDepth << '\n');
  730. // Look at all the tail phis, and compute the critical path extension caused
  731. // by inserting select instructions.
  732. MachineTraceMetrics::Trace TailTrace = MinInstr->getTrace(IfConv.Tail);
  733. for (unsigned i = 0, e = IfConv.PHIs.size(); i != e; ++i) {
  734. SSAIfConv::PHIInfo &PI = IfConv.PHIs[i];
  735. unsigned Slack = TailTrace.getInstrSlack(*PI.PHI);
  736. unsigned MaxDepth = Slack + TailTrace.getInstrCycles(*PI.PHI).Depth;
  737. LLVM_DEBUG(dbgs() << "Slack " << Slack << ":\t" << *PI.PHI);
  738. // The condition is pulled into the critical path.
  739. unsigned CondDepth = adjCycles(BranchDepth, PI.CondCycles);
  740. if (CondDepth > MaxDepth) {
  741. unsigned Extra = CondDepth - MaxDepth;
  742. LLVM_DEBUG(dbgs() << "Condition adds " << Extra << " cycles.\n");
  743. if (Extra > CritLimit) {
  744. LLVM_DEBUG(dbgs() << "Exceeds limit of " << CritLimit << '\n');
  745. return false;
  746. }
  747. }
  748. // The TBB value is pulled into the critical path.
  749. unsigned TDepth = adjCycles(TBBTrace.getPHIDepth(*PI.PHI), PI.TCycles);
  750. if (TDepth > MaxDepth) {
  751. unsigned Extra = TDepth - MaxDepth;
  752. LLVM_DEBUG(dbgs() << "TBB data adds " << Extra << " cycles.\n");
  753. if (Extra > CritLimit) {
  754. LLVM_DEBUG(dbgs() << "Exceeds limit of " << CritLimit << '\n');
  755. return false;
  756. }
  757. }
  758. // The FBB value is pulled into the critical path.
  759. unsigned FDepth = adjCycles(FBBTrace.getPHIDepth(*PI.PHI), PI.FCycles);
  760. if (FDepth > MaxDepth) {
  761. unsigned Extra = FDepth - MaxDepth;
  762. LLVM_DEBUG(dbgs() << "FBB data adds " << Extra << " cycles.\n");
  763. if (Extra > CritLimit) {
  764. LLVM_DEBUG(dbgs() << "Exceeds limit of " << CritLimit << '\n');
  765. return false;
  766. }
  767. }
  768. }
  769. return true;
  770. }
  771. /// Attempt repeated if-conversion on MBB, return true if successful.
  772. ///
  773. bool EarlyIfConverter::tryConvertIf(MachineBasicBlock *MBB) {
  774. bool Changed = false;
  775. while (IfConv.canConvertIf(MBB) && shouldConvertIf()) {
  776. // If-convert MBB and update analyses.
  777. invalidateTraces();
  778. SmallVector<MachineBasicBlock*, 4> RemovedBlocks;
  779. IfConv.convertIf(RemovedBlocks);
  780. Changed = true;
  781. updateDomTree(DomTree, IfConv, RemovedBlocks);
  782. updateLoops(Loops, RemovedBlocks);
  783. }
  784. return Changed;
  785. }
  786. bool EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) {
  787. LLVM_DEBUG(dbgs() << "********** EARLY IF-CONVERSION **********\n"
  788. << "********** Function: " << MF.getName() << '\n');
  789. if (skipFunction(MF.getFunction()))
  790. return false;
  791. // Only run if conversion if the target wants it.
  792. const TargetSubtargetInfo &STI = MF.getSubtarget();
  793. if (!STI.enableEarlyIfConversion())
  794. return false;
  795. TII = STI.getInstrInfo();
  796. TRI = STI.getRegisterInfo();
  797. SchedModel = STI.getSchedModel();
  798. MRI = &MF.getRegInfo();
  799. DomTree = &getAnalysis<MachineDominatorTree>();
  800. Loops = getAnalysisIfAvailable<MachineLoopInfo>();
  801. Traces = &getAnalysis<MachineTraceMetrics>();
  802. MinInstr = nullptr;
  803. bool Changed = false;
  804. IfConv.runOnMachineFunction(MF);
  805. // Visit blocks in dominator tree post-order. The post-order enables nested
  806. // if-conversion in a single pass. The tryConvertIf() function may erase
  807. // blocks, but only blocks dominated by the head block. This makes it safe to
  808. // update the dominator tree while the post-order iterator is still active.
  809. for (auto DomNode : post_order(DomTree))
  810. if (tryConvertIf(DomNode->getBlock()))
  811. Changed = true;
  812. return Changed;
  813. }
  814. //===----------------------------------------------------------------------===//
  815. // EarlyIfPredicator Pass
  816. //===----------------------------------------------------------------------===//
  817. namespace {
  818. class EarlyIfPredicator : public MachineFunctionPass {
  819. const TargetInstrInfo *TII;
  820. const TargetRegisterInfo *TRI;
  821. TargetSchedModel SchedModel;
  822. MachineRegisterInfo *MRI;
  823. MachineDominatorTree *DomTree;
  824. MachineLoopInfo *Loops;
  825. SSAIfConv IfConv;
  826. public:
  827. static char ID;
  828. EarlyIfPredicator() : MachineFunctionPass(ID) {}
  829. void getAnalysisUsage(AnalysisUsage &AU) const override;
  830. bool runOnMachineFunction(MachineFunction &MF) override;
  831. StringRef getPassName() const override { return "Early If-predicator"; }
  832. protected:
  833. bool tryConvertIf(MachineBasicBlock *);
  834. bool shouldConvertIf();
  835. };
  836. } // end anonymous namespace
  837. #undef DEBUG_TYPE
  838. #define DEBUG_TYPE "early-if-predicator"
  839. char EarlyIfPredicator::ID = 0;
  840. char &llvm::EarlyIfPredicatorID = EarlyIfPredicator::ID;
  841. INITIALIZE_PASS_BEGIN(EarlyIfPredicator, DEBUG_TYPE, "Early If Predicator",
  842. false, false)
  843. INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
  844. INITIALIZE_PASS_END(EarlyIfPredicator, DEBUG_TYPE, "Early If Predicator", false,
  845. false)
  846. void EarlyIfPredicator::getAnalysisUsage(AnalysisUsage &AU) const {
  847. AU.addRequired<MachineDominatorTree>();
  848. AU.addPreserved<MachineDominatorTree>();
  849. AU.addRequired<MachineLoopInfo>();
  850. AU.addPreserved<MachineLoopInfo>();
  851. MachineFunctionPass::getAnalysisUsage(AU);
  852. }
  853. /// Apply the target heuristic to decide if the transformation is profitable.
  854. bool EarlyIfPredicator::shouldConvertIf() {
  855. if (IfConv.isTriangle()) {
  856. MachineBasicBlock &IfBlock =
  857. (IfConv.TBB == IfConv.Tail) ? *IfConv.FBB : *IfConv.TBB;
  858. unsigned ExtraPredCost = 0;
  859. unsigned Cycles = 0;
  860. for (MachineInstr &I : IfBlock) {
  861. unsigned NumCycles = SchedModel.computeInstrLatency(&I, false);
  862. if (NumCycles > 1)
  863. Cycles += NumCycles - 1;
  864. ExtraPredCost += TII->getPredicationCost(I);
  865. }
  866. return TII->isProfitableToIfCvt(IfBlock, Cycles, ExtraPredCost,
  867. BranchProbability::getUnknown());
  868. }
  869. unsigned TExtra = 0;
  870. unsigned FExtra = 0;
  871. unsigned TCycle = 0;
  872. unsigned FCycle = 0;
  873. for (MachineInstr &I : *IfConv.TBB) {
  874. unsigned NumCycles = SchedModel.computeInstrLatency(&I, false);
  875. if (NumCycles > 1)
  876. TCycle += NumCycles - 1;
  877. TExtra += TII->getPredicationCost(I);
  878. }
  879. for (MachineInstr &I : *IfConv.FBB) {
  880. unsigned NumCycles = SchedModel.computeInstrLatency(&I, false);
  881. if (NumCycles > 1)
  882. FCycle += NumCycles - 1;
  883. FExtra += TII->getPredicationCost(I);
  884. }
  885. return TII->isProfitableToIfCvt(*IfConv.TBB, TCycle, TExtra, *IfConv.FBB,
  886. FCycle, FExtra,
  887. BranchProbability::getUnknown());
  888. }
  889. /// Attempt repeated if-conversion on MBB, return true if successful.
  890. ///
  891. bool EarlyIfPredicator::tryConvertIf(MachineBasicBlock *MBB) {
  892. bool Changed = false;
  893. while (IfConv.canConvertIf(MBB, /*Predicate*/ true) && shouldConvertIf()) {
  894. // If-convert MBB and update analyses.
  895. SmallVector<MachineBasicBlock *, 4> RemovedBlocks;
  896. IfConv.convertIf(RemovedBlocks, /*Predicate*/ true);
  897. Changed = true;
  898. updateDomTree(DomTree, IfConv, RemovedBlocks);
  899. updateLoops(Loops, RemovedBlocks);
  900. }
  901. return Changed;
  902. }
  903. bool EarlyIfPredicator::runOnMachineFunction(MachineFunction &MF) {
  904. LLVM_DEBUG(dbgs() << "********** EARLY IF-PREDICATOR **********\n"
  905. << "********** Function: " << MF.getName() << '\n');
  906. if (skipFunction(MF.getFunction()))
  907. return false;
  908. const TargetSubtargetInfo &STI = MF.getSubtarget();
  909. TII = STI.getInstrInfo();
  910. TRI = STI.getRegisterInfo();
  911. MRI = &MF.getRegInfo();
  912. SchedModel.init(&STI);
  913. DomTree = &getAnalysis<MachineDominatorTree>();
  914. Loops = getAnalysisIfAvailable<MachineLoopInfo>();
  915. bool Changed = false;
  916. IfConv.runOnMachineFunction(MF);
  917. // Visit blocks in dominator tree post-order. The post-order enables nested
  918. // if-conversion in a single pass. The tryConvertIf() function may erase
  919. // blocks, but only blocks dominated by the head block. This makes it safe to
  920. // update the dominator tree while the post-order iterator is still active.
  921. for (auto DomNode : post_order(DomTree))
  922. if (tryConvertIf(DomNode->getBlock()))
  923. Changed = true;
  924. return Changed;
  925. }