blob: 58f80bd46dc3c76e81164d229e703ce284064323 [file] [log] [blame]
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +00001//===-- CoalesceBranches.cpp - Coalesce blocks with the same condition ---===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +00006//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// Coalesce basic blocks guarded by the same branch condition into a single
11/// basic block.
12///
13//===----------------------------------------------------------------------===//
14
Lei Huang34e66212017-09-12 18:39:11 +000015#include "PPC.h"
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000016#include "llvm/ADT/BitVector.h"
17#include "llvm/ADT/Statistic.h"
18#include "llvm/CodeGen/MachineDominators.h"
19#include "llvm/CodeGen/MachineFunctionPass.h"
20#include "llvm/CodeGen/MachinePostDominators.h"
21#include "llvm/CodeGen/MachineRegisterInfo.h"
22#include "llvm/CodeGen/Passes.h"
David Blaikie1be62f02017-11-03 22:32:11 +000023#include "llvm/CodeGen/TargetFrameLowering.h"
David Blaikie3f833ed2017-11-08 01:01:31 +000024#include "llvm/CodeGen/TargetInstrInfo.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000025#include "llvm/CodeGen/TargetSubtargetInfo.h"
David Blaikie3f833ed2017-11-08 01:01:31 +000026#include "llvm/Support/Debug.h"
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000027
28using namespace llvm;
29
Lei Huang34e66212017-09-12 18:39:11 +000030#define DEBUG_TYPE "ppc-branch-coalescing"
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000031
32STATISTIC(NumBlocksCoalesced, "Number of blocks coalesced");
33STATISTIC(NumPHINotMoved, "Number of PHI Nodes that cannot be merged");
34STATISTIC(NumBlocksNotCoalesced, "Number of blocks not coalesced");
35
Lei Huang34e66212017-09-12 18:39:11 +000036namespace llvm {
37 void initializePPCBranchCoalescingPass(PassRegistry&);
38}
39
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000040//===----------------------------------------------------------------------===//
Lei Huang34e66212017-09-12 18:39:11 +000041// PPCBranchCoalescing
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000042//===----------------------------------------------------------------------===//
43///
44/// Improve scheduling by coalescing branches that depend on the same condition.
45/// This pass looks for blocks that are guarded by the same branch condition
46/// and attempts to merge the blocks together. Such opportunities arise from
47/// the expansion of select statements in the IR.
48///
Lei Huang34e66212017-09-12 18:39:11 +000049/// This pass does not handle implicit operands on branch statements. In order
50/// to run on targets that use implicit operands, changes need to be made in the
51/// canCoalesceBranch and canMerge methods.
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000052///
Lei Huang34e66212017-09-12 18:39:11 +000053/// Example: the following LLVM IR
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000054///
Lei Huang34e66212017-09-12 18:39:11 +000055/// %test = icmp eq i32 %x 0
56/// %tmp1 = select i1 %test, double %a, double 2.000000e-03
57/// %tmp2 = select i1 %test, double %b, double 5.000000e-03
58///
59/// expands to the following machine code:
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000060///
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000061/// %bb.0: derived from LLVM BB %entry
Francis Visoiu Mistrihfb7b14f72018-02-09 01:14:44 +000062/// liveins: %f1 %f3 %x6
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000063/// <SNIP1>
Francis Visoiu Mistriha8a83d12017-12-07 10:40:31 +000064/// %0 = COPY %f1; F8RC:%0
65/// %5 = CMPLWI killed %4, 0; CRRC:%5 GPRC:%4
66/// %8 = LXSDX %zero8, killed %7, implicit %rm;
Francis Visoiu Mistrih93ef1452017-11-30 12:12:19 +000067/// mem:LD8[ConstantPool] F8RC:%8 G8RC:%7
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000068/// BCC 76, %5, <%bb.2>; CRRC:%5
69/// Successors according to CFG: %bb.1(?%) %bb.2(?%)
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000070///
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000071/// %bb.1: derived from LLVM BB %entry
72/// Predecessors according to CFG: %bb.0
73/// Successors according to CFG: %bb.2(?%)
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000074///
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000075/// %bb.2: derived from LLVM BB %entry
76/// Predecessors according to CFG: %bb.0 %bb.1
Francis Visoiu Mistriha8a83d12017-12-07 10:40:31 +000077/// %9 = PHI %8, <%bb.1>, %0, <%bb.0>;
Francis Visoiu Mistrih93ef1452017-11-30 12:12:19 +000078/// F8RC:%9,%8,%0
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000079/// <SNIP2>
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000080/// BCC 76, %5, <%bb.4>; CRRC:%5
81/// Successors according to CFG: %bb.3(?%) %bb.4(?%)
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000082///
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000083/// %bb.3: derived from LLVM BB %entry
84/// Predecessors according to CFG: %bb.2
85/// Successors according to CFG: %bb.4(?%)
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000086///
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000087/// %bb.4: derived from LLVM BB %entry
88/// Predecessors according to CFG: %bb.2 %bb.3
Francis Visoiu Mistriha8a83d12017-12-07 10:40:31 +000089/// %13 = PHI %12, <%bb.3>, %2, <%bb.2>;
Francis Visoiu Mistrih93ef1452017-11-30 12:12:19 +000090/// F8RC:%13,%12,%2
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000091/// <SNIP3>
Francis Visoiu Mistriha8a83d12017-12-07 10:40:31 +000092/// BLR8 implicit %lr8, implicit %rm, implicit %f1
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000093///
94/// When this pattern is detected, branch coalescing will try to collapse
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000095/// it by moving code in %bb.2 to %bb.0 and/or %bb.4 and removing %bb.3.
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +000096///
97/// If all conditions are meet, IR should collapse to:
98///
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000099/// %bb.0: derived from LLVM BB %entry
Francis Visoiu Mistrihfb7b14f72018-02-09 01:14:44 +0000100/// liveins: %f1 %f3 %x6
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000101/// <SNIP1>
Francis Visoiu Mistriha8a83d12017-12-07 10:40:31 +0000102/// %0 = COPY %f1; F8RC:%0
103/// %5 = CMPLWI killed %4, 0; CRRC:%5 GPRC:%4
104/// %8 = LXSDX %zero8, killed %7, implicit %rm;
Francis Visoiu Mistrih93ef1452017-11-30 12:12:19 +0000105/// mem:LD8[ConstantPool] F8RC:%8 G8RC:%7
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000106/// <SNIP2>
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +0000107/// BCC 76, %5, <%bb.4>; CRRC:%5
108/// Successors according to CFG: %bb.1(0x2aaaaaaa / 0x80000000 = 33.33%)
109/// %bb.4(0x55555554 / 0x80000000 = 66.67%)
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000110///
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +0000111/// %bb.1: derived from LLVM BB %entry
112/// Predecessors according to CFG: %bb.0
113/// Successors according to CFG: %bb.4(0x40000000 / 0x80000000 = 50.00%)
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000114///
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +0000115/// %bb.4: derived from LLVM BB %entry
116/// Predecessors according to CFG: %bb.0 %bb.1
Francis Visoiu Mistriha8a83d12017-12-07 10:40:31 +0000117/// %9 = PHI %8, <%bb.1>, %0, <%bb.0>;
Francis Visoiu Mistrih93ef1452017-11-30 12:12:19 +0000118/// F8RC:%9,%8,%0
Francis Visoiu Mistriha8a83d12017-12-07 10:40:31 +0000119/// %13 = PHI %12, <%bb.1>, %2, <%bb.0>;
Francis Visoiu Mistrih93ef1452017-11-30 12:12:19 +0000120/// F8RC:%13,%12,%2
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000121/// <SNIP3>
Francis Visoiu Mistriha8a83d12017-12-07 10:40:31 +0000122/// BLR8 implicit %lr8, implicit %rm, implicit %f1
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000123///
124/// Branch Coalescing does not split blocks, it moves everything in the same
125/// direction ensuring it does not break use/definition semantics.
126///
127/// PHI nodes and its corresponding use instructions are moved to its successor
128/// block if there are no uses within the successor block PHI nodes. PHI
129/// node ordering cannot be assumed.
130///
131/// Non-PHI can be moved up to the predecessor basic block or down to the
132/// successor basic block following any PHI instructions. Whether it moves
133/// up or down depends on whether the register(s) defined in the instructions
134/// are used in current block or in any PHI instructions at the beginning of
135/// the successor block.
136
137namespace {
138
Lei Huang34e66212017-09-12 18:39:11 +0000139class PPCBranchCoalescing : public MachineFunctionPass {
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000140 struct CoalescingCandidateInfo {
Simon Pilgrimb01bb3a2017-03-03 12:09:11 +0000141 MachineBasicBlock *BranchBlock; // Block containing the branch
142 MachineBasicBlock *BranchTargetBlock; // Block branched to
143 MachineBasicBlock *FallThroughBlock; // Fall-through if branch not taken
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000144 SmallVector<MachineOperand, 4> Cond;
145 bool MustMoveDown;
146 bool MustMoveUp;
147
148 CoalescingCandidateInfo();
149 void clear();
150 };
151
152 MachineDominatorTree *MDT;
153 MachinePostDominatorTree *MPDT;
154 const TargetInstrInfo *TII;
155 MachineRegisterInfo *MRI;
156
157 void initialize(MachineFunction &F);
158 bool canCoalesceBranch(CoalescingCandidateInfo &Cand);
159 bool identicalOperands(ArrayRef<MachineOperand> OperandList1,
160 ArrayRef<MachineOperand> OperandList2) const;
161 bool validateCandidates(CoalescingCandidateInfo &SourceRegion,
162 CoalescingCandidateInfo &TargetRegion) const;
163
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000164public:
165 static char ID;
166
Lei Huang34e66212017-09-12 18:39:11 +0000167 PPCBranchCoalescing() : MachineFunctionPass(ID) {
168 initializePPCBranchCoalescingPass(*PassRegistry::getPassRegistry());
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000169 }
170
171 void getAnalysisUsage(AnalysisUsage &AU) const override {
172 AU.addRequired<MachineDominatorTree>();
173 AU.addRequired<MachinePostDominatorTree>();
174 MachineFunctionPass::getAnalysisUsage(AU);
175 }
176
177 StringRef getPassName() const override { return "Branch Coalescing"; }
178
179 bool mergeCandidates(CoalescingCandidateInfo &SourceRegion,
180 CoalescingCandidateInfo &TargetRegion);
Simon Pilgrim455e2f32017-03-10 22:53:19 +0000181 bool canMoveToBeginning(const MachineInstr &MI,
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000182 const MachineBasicBlock &MBB) const;
Simon Pilgrim455e2f32017-03-10 22:53:19 +0000183 bool canMoveToEnd(const MachineInstr &MI,
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000184 const MachineBasicBlock &MBB) const;
185 bool canMerge(CoalescingCandidateInfo &SourceRegion,
186 CoalescingCandidateInfo &TargetRegion) const;
187 void moveAndUpdatePHIs(MachineBasicBlock *SourceRegionMBB,
188 MachineBasicBlock *TargetRegionMBB);
189 bool runOnMachineFunction(MachineFunction &MF) override;
190};
191} // End anonymous namespace.
192
Lei Huang34e66212017-09-12 18:39:11 +0000193char PPCBranchCoalescing::ID = 0;
194/// createPPCBranchCoalescingPass - returns an instance of the Branch Coalescing
195/// Pass
196FunctionPass *llvm::createPPCBranchCoalescingPass() {
197 return new PPCBranchCoalescing();
198}
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000199
Lei Huang34e66212017-09-12 18:39:11 +0000200INITIALIZE_PASS_BEGIN(PPCBranchCoalescing, DEBUG_TYPE,
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000201 "Branch Coalescing", false, false)
202INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
203INITIALIZE_PASS_DEPENDENCY(MachinePostDominatorTree)
Lei Huang34e66212017-09-12 18:39:11 +0000204INITIALIZE_PASS_END(PPCBranchCoalescing, DEBUG_TYPE, "Branch Coalescing",
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000205 false, false)
206
Lei Huang34e66212017-09-12 18:39:11 +0000207PPCBranchCoalescing::CoalescingCandidateInfo::CoalescingCandidateInfo()
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000208 : BranchBlock(nullptr), BranchTargetBlock(nullptr),
209 FallThroughBlock(nullptr), MustMoveDown(false), MustMoveUp(false) {}
210
Lei Huang34e66212017-09-12 18:39:11 +0000211void PPCBranchCoalescing::CoalescingCandidateInfo::clear() {
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000212 BranchBlock = nullptr;
213 BranchTargetBlock = nullptr;
214 FallThroughBlock = nullptr;
215 Cond.clear();
216 MustMoveDown = false;
217 MustMoveUp = false;
218}
219
Lei Huang34e66212017-09-12 18:39:11 +0000220void PPCBranchCoalescing::initialize(MachineFunction &MF) {
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000221 MDT = &getAnalysis<MachineDominatorTree>();
222 MPDT = &getAnalysis<MachinePostDominatorTree>();
223 TII = MF.getSubtarget().getInstrInfo();
224 MRI = &MF.getRegInfo();
225}
226
227///
228/// Analyze the branch statement to determine if it can be coalesced. This
229/// method analyses the branch statement for the given candidate to determine
230/// if it can be coalesced. If the branch can be coalesced, then the
231/// BranchTargetBlock and the FallThroughBlock are recorded in the specified
232/// Candidate.
233///
234///\param[in,out] Cand The coalescing candidate to analyze
235///\return true if and only if the branch can be coalesced, false otherwise
236///
Lei Huang34e66212017-09-12 18:39:11 +0000237bool PPCBranchCoalescing::canCoalesceBranch(CoalescingCandidateInfo &Cand) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000238 LLVM_DEBUG(dbgs() << "Determine if branch block "
239 << Cand.BranchBlock->getNumber() << " can be coalesced:");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000240 MachineBasicBlock *FalseMBB = nullptr;
241
242 if (TII->analyzeBranch(*Cand.BranchBlock, Cand.BranchTargetBlock, FalseMBB,
243 Cand.Cond)) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000244 LLVM_DEBUG(dbgs() << "TII unable to Analyze Branch - skip\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000245 return false;
246 }
247
248 for (auto &I : Cand.BranchBlock->terminators()) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000249 LLVM_DEBUG(dbgs() << "Looking at terminator : " << I << "\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000250 if (!I.isBranch())
251 continue;
252
Lei Huang34e66212017-09-12 18:39:11 +0000253 // The analyzeBranch method does not include any implicit operands.
254 // This is not an issue on PPC but must be handled on other targets.
255 // For this pass to be made target-independent, the analyzeBranch API
256 // need to be updated to support implicit operands and there would
257 // need to be a way to verify that any implicit operands would not be
258 // clobbered by merging blocks. This would include identifying the
259 // implicit operands as well as the basic block they are defined in.
260 // This could be done by changing the analyzeBranch API to have it also
261 // record and return the implicit operands and the blocks where they are
262 // defined. Alternatively, the BranchCoalescing code would need to be
263 // extended to identify the implicit operands. The analysis in canMerge
264 // must then be extended to prove that none of the implicit operands are
265 // changed in the blocks that are combined during coalescing.
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000266 if (I.getNumOperands() != I.getNumExplicitOperands()) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000267 LLVM_DEBUG(dbgs() << "Terminator contains implicit operands - skip : "
268 << I << "\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000269 return false;
270 }
271 }
272
273 if (Cand.BranchBlock->isEHPad() || Cand.BranchBlock->hasEHPadSuccessor()) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000274 LLVM_DEBUG(dbgs() << "EH Pad - skip\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000275 return false;
276 }
277
278 // For now only consider triangles (i.e, BranchTargetBlock is set,
279 // FalseMBB is null, and BranchTargetBlock is a successor to BranchBlock)
Simon Pilgrim83c37c42017-03-10 22:44:47 +0000280 if (!Cand.BranchTargetBlock || FalseMBB ||
281 !Cand.BranchBlock->isSuccessor(Cand.BranchTargetBlock)) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000282 LLVM_DEBUG(dbgs() << "Does not form a triangle - skip\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000283 return false;
284 }
285
286 // Ensure there are only two successors
287 if (Cand.BranchBlock->succ_size() != 2) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000288 LLVM_DEBUG(dbgs() << "Does not have 2 successors - skip\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000289 return false;
290 }
291
292 // Sanity check - the block must be able to fall through
293 assert(Cand.BranchBlock->canFallThrough() &&
294 "Expecting the block to fall through!");
295
Simon Pilgrim455e2f32017-03-10 22:53:19 +0000296 // We have already ensured there are exactly two successors to
297 // BranchBlock and that BranchTargetBlock is a successor to BranchBlock.
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000298 // Ensure the single fall though block is empty.
Simon Pilgrim455e2f32017-03-10 22:53:19 +0000299 MachineBasicBlock *Succ =
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000300 (*Cand.BranchBlock->succ_begin() == Cand.BranchTargetBlock)
301 ? *Cand.BranchBlock->succ_rbegin()
302 : *Cand.BranchBlock->succ_begin();
303
304 assert(Succ && "Expecting a valid fall-through block\n");
305
306 if (!Succ->empty()) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000307 LLVM_DEBUG(dbgs() << "Fall-through block contains code -- skip\n");
308 return false;
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000309 }
310
311 if (!Succ->isSuccessor(Cand.BranchTargetBlock)) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000312 LLVM_DEBUG(
313 dbgs()
314 << "Successor of fall through block is not branch taken block\n");
315 return false;
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000316 }
317
318 Cand.FallThroughBlock = Succ;
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000319 LLVM_DEBUG(dbgs() << "Valid Candidate\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000320 return true;
321}
322
323///
324/// Determine if the two operand lists are identical
325///
326/// \param[in] OpList1 operand list
327/// \param[in] OpList2 operand list
328/// \return true if and only if the operands lists are identical
329///
Lei Huang34e66212017-09-12 18:39:11 +0000330bool PPCBranchCoalescing::identicalOperands(
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000331 ArrayRef<MachineOperand> OpList1, ArrayRef<MachineOperand> OpList2) const {
332
333 if (OpList1.size() != OpList2.size()) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000334 LLVM_DEBUG(dbgs() << "Operand list is different size\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000335 return false;
336 }
337
338 for (unsigned i = 0; i < OpList1.size(); ++i) {
339 const MachineOperand &Op1 = OpList1[i];
340 const MachineOperand &Op2 = OpList2[i];
341
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000342 LLVM_DEBUG(dbgs() << "Op1: " << Op1 << "\n"
343 << "Op2: " << Op2 << "\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000344
345 if (Op1.isIdenticalTo(Op2)) {
Lei Huang34e66212017-09-12 18:39:11 +0000346 // filter out instructions with physical-register uses
347 if (Op1.isReg() && TargetRegisterInfo::isPhysicalRegister(Op1.getReg())
348 // If the physical register is constant then we can assume the value
349 // has not changed between uses.
350 && !(Op1.isUse() && MRI->isConstantPhysReg(Op1.getReg()))) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000351 LLVM_DEBUG(dbgs() << "The operands are not provably identical.\n");
Lei Huang34e66212017-09-12 18:39:11 +0000352 return false;
353 }
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000354 LLVM_DEBUG(dbgs() << "Op1 and Op2 are identical!\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000355 continue;
356 }
357
358 // If the operands are not identical, but are registers, check to see if the
359 // definition of the register produces the same value. If they produce the
360 // same value, consider them to be identical.
361 if (Op1.isReg() && Op2.isReg() &&
362 TargetRegisterInfo::isVirtualRegister(Op1.getReg()) &&
363 TargetRegisterInfo::isVirtualRegister(Op2.getReg())) {
364 MachineInstr *Op1Def = MRI->getVRegDef(Op1.getReg());
365 MachineInstr *Op2Def = MRI->getVRegDef(Op2.getReg());
366 if (TII->produceSameValue(*Op1Def, *Op2Def, MRI)) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000367 LLVM_DEBUG(dbgs() << "Op1Def: " << *Op1Def << " and " << *Op2Def
368 << " produce the same value!\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000369 } else {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000370 LLVM_DEBUG(dbgs() << "Operands produce different values\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000371 return false;
372 }
373 } else {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000374 LLVM_DEBUG(dbgs() << "The operands are not provably identical.\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000375 return false;
376 }
377 }
Lei Huang34e66212017-09-12 18:39:11 +0000378
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000379 return true;
380}
381
382///
Simon Pilgrim455e2f32017-03-10 22:53:19 +0000383/// Moves ALL PHI instructions in SourceMBB to beginning of TargetMBB
384/// and update them to refer to the new block. PHI node ordering
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000385/// cannot be assumed so it does not matter where the PHI instructions
386/// are moved to in TargetMBB.
387///
388/// \param[in] SourceMBB block to move PHI instructions from
389/// \param[in] TargetMBB block to move PHI instructions to
390///
Lei Huang34e66212017-09-12 18:39:11 +0000391void PPCBranchCoalescing::moveAndUpdatePHIs(MachineBasicBlock *SourceMBB,
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000392 MachineBasicBlock *TargetMBB) {
393
394 MachineBasicBlock::iterator MI = SourceMBB->begin();
395 MachineBasicBlock::iterator ME = SourceMBB->getFirstNonPHI();
396
397 if (MI == ME) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000398 LLVM_DEBUG(dbgs() << "SourceMBB contains no PHI instructions.\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000399 return;
400 }
401
402 // Update all PHI instructions in SourceMBB and move to top of TargetMBB
403 for (MachineBasicBlock::iterator Iter = MI; Iter != ME; Iter++) {
404 MachineInstr &PHIInst = *Iter;
405 for (unsigned i = 2, e = PHIInst.getNumOperands() + 1; i != e; i += 2) {
406 MachineOperand &MO = PHIInst.getOperand(i);
407 if (MO.getMBB() == SourceMBB)
408 MO.setMBB(TargetMBB);
409 }
410 }
411 TargetMBB->splice(TargetMBB->begin(), SourceMBB, MI, ME);
412}
413
414///
415/// This function checks if MI can be moved to the beginning of the TargetMBB
Simon Pilgrim455e2f32017-03-10 22:53:19 +0000416/// following PHI instructions. A MI instruction can be moved to beginning of
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000417/// the TargetMBB if there are no uses of it within the TargetMBB PHI nodes.
418///
419/// \param[in] MI the machine instruction to move.
Simon Pilgrim7b227fe2017-03-02 18:59:07 +0000420/// \param[in] TargetMBB the machine basic block to move to
Simon Pilgrim455e2f32017-03-10 22:53:19 +0000421/// \return true if it is safe to move MI to beginning of TargetMBB,
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000422/// false otherwise.
423///
Lei Huang34e66212017-09-12 18:39:11 +0000424bool PPCBranchCoalescing::canMoveToBeginning(const MachineInstr &MI,
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000425 const MachineBasicBlock &TargetMBB
426 ) const {
427
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000428 LLVM_DEBUG(dbgs() << "Checking if " << MI << " can move to beginning of "
429 << TargetMBB.getNumber() << "\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000430
431 for (auto &Def : MI.defs()) { // Looking at Def
432 for (auto &Use : MRI->use_instructions(Def.getReg())) {
433 if (Use.isPHI() && Use.getParent() == &TargetMBB) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000434 LLVM_DEBUG(dbgs() << " *** used in a PHI -- cannot move ***\n");
435 return false;
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000436 }
437 }
438 }
439
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000440 LLVM_DEBUG(dbgs() << " Safe to move to the beginning.\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000441 return true;
442}
443
444///
445/// This function checks if MI can be moved to the end of the TargetMBB,
446/// immediately before the first terminator. A MI instruction can be moved
Simon Pilgrim455e2f32017-03-10 22:53:19 +0000447/// to then end of the TargetMBB if no PHI node defines what MI uses within
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000448/// it's own MBB.
449///
450/// \param[in] MI the machine instruction to move.
Simon Pilgrim7b227fe2017-03-02 18:59:07 +0000451/// \param[in] TargetMBB the machine basic block to move to
Simon Pilgrim455e2f32017-03-10 22:53:19 +0000452/// \return true if it is safe to move MI to end of TargetMBB,
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000453/// false otherwise.
454///
Lei Huang34e66212017-09-12 18:39:11 +0000455bool PPCBranchCoalescing::canMoveToEnd(const MachineInstr &MI,
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000456 const MachineBasicBlock &TargetMBB
457 ) const {
458
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000459 LLVM_DEBUG(dbgs() << "Checking if " << MI << " can move to end of "
460 << TargetMBB.getNumber() << "\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000461
462 for (auto &Use : MI.uses()) {
463 if (Use.isReg() && TargetRegisterInfo::isVirtualRegister(Use.getReg())) {
464 MachineInstr *DefInst = MRI->getVRegDef(Use.getReg());
465 if (DefInst->isPHI() && DefInst->getParent() == MI.getParent()) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000466 LLVM_DEBUG(dbgs() << " *** Cannot move this instruction ***\n");
Simon Pilgrim455e2f32017-03-10 22:53:19 +0000467 return false;
468 } else {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000469 LLVM_DEBUG(
470 dbgs() << " *** def is in another block -- safe to move!\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000471 }
472 }
473 }
474
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000475 LLVM_DEBUG(dbgs() << " Safe to move to the end.\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000476 return true;
477}
478
479///
480/// This method checks to ensure the two coalescing candidates follows the
481/// expected pattern required for coalescing.
482///
483/// \param[in] SourceRegion The candidate to move statements from
484/// \param[in] TargetRegion The candidate to move statements to
485/// \return true if all instructions in SourceRegion.BranchBlock can be merged
486/// into a block in TargetRegion; false otherwise.
487///
Lei Huang34e66212017-09-12 18:39:11 +0000488bool PPCBranchCoalescing::validateCandidates(
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000489 CoalescingCandidateInfo &SourceRegion,
490 CoalescingCandidateInfo &TargetRegion) const {
491
492 if (TargetRegion.BranchTargetBlock != SourceRegion.BranchBlock)
493 llvm_unreachable("Expecting SourceRegion to immediately follow TargetRegion");
494 else if (!MDT->dominates(TargetRegion.BranchBlock, SourceRegion.BranchBlock))
495 llvm_unreachable("Expecting TargetRegion to dominate SourceRegion");
496 else if (!MPDT->dominates(SourceRegion.BranchBlock, TargetRegion.BranchBlock))
497 llvm_unreachable("Expecting SourceRegion to post-dominate TargetRegion");
498 else if (!TargetRegion.FallThroughBlock->empty() ||
499 !SourceRegion.FallThroughBlock->empty())
500 llvm_unreachable("Expecting fall-through blocks to be empty");
501
502 return true;
503}
504
505///
506/// This method determines whether the two coalescing candidates can be merged.
507/// In order to be merged, all instructions must be able to
508/// 1. Move to the beginning of the SourceRegion.BranchTargetBlock;
509/// 2. Move to the end of the TargetRegion.BranchBlock.
510/// Merging involves moving the instructions in the
511/// TargetRegion.BranchTargetBlock (also SourceRegion.BranchBlock).
512///
Simon Pilgrim455e2f32017-03-10 22:53:19 +0000513/// This function first try to move instructions from the
514/// TargetRegion.BranchTargetBlock down, to the beginning of the
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000515/// SourceRegion.BranchTargetBlock. This is not possible if any register defined
516/// in TargetRegion.BranchTargetBlock is used in a PHI node in the
517/// SourceRegion.BranchTargetBlock. In this case, check whether the statement
518/// can be moved up, to the end of the TargetRegion.BranchBlock (immediately
519/// before the branch statement). If it cannot move, then these blocks cannot
520/// be merged.
521///
522/// Note that there is no analysis for moving instructions past the fall-through
Simon Pilgrim455e2f32017-03-10 22:53:19 +0000523/// blocks because they are confirmed to be empty. An assert is thrown if they
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000524/// are not.
525///
526/// \param[in] SourceRegion The candidate to move statements from
527/// \param[in] TargetRegion The candidate to move statements to
528/// \return true if all instructions in SourceRegion.BranchBlock can be merged
529/// into a block in TargetRegion, false otherwise.
530///
Lei Huang34e66212017-09-12 18:39:11 +0000531bool PPCBranchCoalescing::canMerge(CoalescingCandidateInfo &SourceRegion,
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000532 CoalescingCandidateInfo &TargetRegion) const {
533 if (!validateCandidates(SourceRegion, TargetRegion))
534 return false;
535
536 // Walk through PHI nodes first and see if they force the merge into the
537 // SourceRegion.BranchTargetBlock.
538 for (MachineBasicBlock::iterator
539 I = SourceRegion.BranchBlock->instr_begin(),
540 E = SourceRegion.BranchBlock->getFirstNonPHI();
541 I != E; ++I) {
542 for (auto &Def : I->defs())
543 for (auto &Use : MRI->use_instructions(Def.getReg())) {
544 if (Use.isPHI() && Use.getParent() == SourceRegion.BranchTargetBlock) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000545 LLVM_DEBUG(dbgs()
546 << "PHI " << *I
547 << " defines register used in another "
548 "PHI within branch target block -- can't merge\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000549 NumPHINotMoved++;
550 return false;
551 }
552 if (Use.getParent() == SourceRegion.BranchBlock) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000553 LLVM_DEBUG(dbgs() << "PHI " << *I
554 << " defines register used in this "
555 "block -- all must move down\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000556 SourceRegion.MustMoveDown = true;
557 }
558 }
559 }
560
561 // Walk through the MI to see if they should be merged into
562 // TargetRegion.BranchBlock (up) or SourceRegion.BranchTargetBlock (down)
563 for (MachineBasicBlock::iterator
564 I = SourceRegion.BranchBlock->getFirstNonPHI(),
565 E = SourceRegion.BranchBlock->end();
566 I != E; ++I) {
567 if (!canMoveToBeginning(*I, *SourceRegion.BranchTargetBlock)) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000568 LLVM_DEBUG(dbgs() << "Instruction " << *I
569 << " cannot move down - must move up!\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000570 SourceRegion.MustMoveUp = true;
571 }
572 if (!canMoveToEnd(*I, *TargetRegion.BranchBlock)) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000573 LLVM_DEBUG(dbgs() << "Instruction " << *I
574 << " cannot move up - must move down!\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000575 SourceRegion.MustMoveDown = true;
576 }
577 }
578
579 return (SourceRegion.MustMoveUp && SourceRegion.MustMoveDown) ? false : true;
580}
581
582/// Merge the instructions from SourceRegion.BranchBlock,
583/// SourceRegion.BranchTargetBlock, and SourceRegion.FallThroughBlock into
584/// TargetRegion.BranchBlock, TargetRegion.BranchTargetBlock and
585/// TargetRegion.FallThroughBlock respectively.
586///
587/// The successors for blocks in TargetRegion will be updated to use the
588/// successors from blocks in SourceRegion. Finally, the blocks in SourceRegion
589/// will be removed from the function.
590///
591/// A region consists of a BranchBlock, a FallThroughBlock, and a
592/// BranchTargetBlock. Branch coalesce works on patterns where the
593/// TargetRegion's BranchTargetBlock must also be the SourceRegions's
594/// BranchBlock.
595///
596/// Before mergeCandidates:
597///
598/// +---------------------------+
599/// | TargetRegion.BranchBlock |
600/// +---------------------------+
601/// / |
602/// / +--------------------------------+
603/// | | TargetRegion.FallThroughBlock |
604/// \ +--------------------------------+
605/// \ |
606/// +----------------------------------+
607/// | TargetRegion.BranchTargetBlock |
608/// | SourceRegion.BranchBlock |
609/// +----------------------------------+
610/// / |
611/// / +--------------------------------+
612/// | | SourceRegion.FallThroughBlock |
613/// \ +--------------------------------+
614/// \ |
615/// +----------------------------------+
616/// | SourceRegion.BranchTargetBlock |
617/// +----------------------------------+
618///
619/// After mergeCandidates:
620///
621/// +-----------------------------+
622/// | TargetRegion.BranchBlock |
623/// | SourceRegion.BranchBlock |
624/// +-----------------------------+
625/// / |
626/// / +---------------------------------+
627/// | | TargetRegion.FallThroughBlock |
628/// | | SourceRegion.FallThroughBlock |
629/// \ +---------------------------------+
630/// \ |
631/// +----------------------------------+
632/// | SourceRegion.BranchTargetBlock |
633/// +----------------------------------+
634///
635/// \param[in] SourceRegion The candidate to move blocks from
636/// \param[in] TargetRegion The candidate to move blocks to
637///
Lei Huang34e66212017-09-12 18:39:11 +0000638bool PPCBranchCoalescing::mergeCandidates(CoalescingCandidateInfo &SourceRegion,
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000639 CoalescingCandidateInfo &TargetRegion) {
640
641 if (SourceRegion.MustMoveUp && SourceRegion.MustMoveDown) {
642 llvm_unreachable("Cannot have both MustMoveDown and MustMoveUp set!");
643 return false;
644 }
645
646 if (!validateCandidates(SourceRegion, TargetRegion))
647 return false;
648
649 // Start the merging process by first handling the BranchBlock.
650 // Move any PHIs in SourceRegion.BranchBlock down to the branch-taken block
651 moveAndUpdatePHIs(SourceRegion.BranchBlock, SourceRegion.BranchTargetBlock);
652
653 // Move remaining instructions in SourceRegion.BranchBlock into
654 // TargetRegion.BranchBlock
655 MachineBasicBlock::iterator firstInstr =
656 SourceRegion.BranchBlock->getFirstNonPHI();
657 MachineBasicBlock::iterator lastInstr =
658 SourceRegion.BranchBlock->getFirstTerminator();
659
660 MachineBasicBlock *Source = SourceRegion.MustMoveDown
661 ? SourceRegion.BranchTargetBlock
662 : TargetRegion.BranchBlock;
663
664 MachineBasicBlock::iterator Target =
665 SourceRegion.MustMoveDown
666 ? SourceRegion.BranchTargetBlock->getFirstNonPHI()
667 : TargetRegion.BranchBlock->getFirstTerminator();
668
669 Source->splice(Target, SourceRegion.BranchBlock, firstInstr, lastInstr);
670
671 // Once PHI and instructions have been moved we need to clean up the
672 // control flow.
673
674 // Remove SourceRegion.FallThroughBlock before transferring successors of
675 // SourceRegion.BranchBlock to TargetRegion.BranchBlock.
676 SourceRegion.BranchBlock->removeSuccessor(SourceRegion.FallThroughBlock);
677 TargetRegion.BranchBlock->transferSuccessorsAndUpdatePHIs(
678 SourceRegion.BranchBlock);
679 // Update branch in TargetRegion.BranchBlock to jump to
680 // SourceRegion.BranchTargetBlock
681 // In this case, TargetRegion.BranchTargetBlock == SourceRegion.BranchBlock.
682 TargetRegion.BranchBlock->ReplaceUsesOfBlockWith(
683 SourceRegion.BranchBlock, SourceRegion.BranchTargetBlock);
684 // Remove the branch statement(s) in SourceRegion.BranchBlock
685 MachineBasicBlock::iterator I =
686 SourceRegion.BranchBlock->terminators().begin();
687 while (I != SourceRegion.BranchBlock->terminators().end()) {
688 MachineInstr &CurrInst = *I;
689 ++I;
690 if (CurrInst.isBranch())
691 CurrInst.eraseFromParent();
692 }
693
694 // Fall-through block should be empty since this is part of the condition
695 // to coalesce the branches.
696 assert(TargetRegion.FallThroughBlock->empty() &&
697 "FallThroughBlocks should be empty!");
698
Simon Pilgrim455e2f32017-03-10 22:53:19 +0000699 // Transfer successor information and move PHIs down to the
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000700 // branch-taken block.
701 TargetRegion.FallThroughBlock->transferSuccessorsAndUpdatePHIs(
702 SourceRegion.FallThroughBlock);
703 TargetRegion.FallThroughBlock->removeSuccessor(SourceRegion.BranchBlock);
704
705 // Remove the blocks from the function.
706 assert(SourceRegion.BranchBlock->empty() &&
707 "Expecting branch block to be empty!");
708 SourceRegion.BranchBlock->eraseFromParent();
709
710 assert(SourceRegion.FallThroughBlock->empty() &&
711 "Expecting fall-through block to be empty!\n");
712 SourceRegion.FallThroughBlock->eraseFromParent();
713
714 NumBlocksCoalesced++;
715 return true;
716}
717
Lei Huang34e66212017-09-12 18:39:11 +0000718bool PPCBranchCoalescing::runOnMachineFunction(MachineFunction &MF) {
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000719
Matthias Braunf1caa282017-12-15 22:22:58 +0000720 if (skipFunction(MF.getFunction()) || MF.empty())
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000721 return false;
722
723 bool didSomething = false;
724
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000725 LLVM_DEBUG(dbgs() << "******** Branch Coalescing ********\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000726 initialize(MF);
727
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000728 LLVM_DEBUG(dbgs() << "Function: "; MF.dump(); dbgs() << "\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000729
730 CoalescingCandidateInfo Cand1, Cand2;
731 // Walk over blocks and find candidates to merge
732 // Continue trying to merge with the first candidate found, as long as merging
733 // is successfull.
734 for (MachineBasicBlock &MBB : MF) {
735 bool MergedCandidates = false;
736 do {
737 MergedCandidates = false;
738 Cand1.clear();
739 Cand2.clear();
740
741 Cand1.BranchBlock = &MBB;
742
743 // If unable to coalesce the branch, then continue to next block
744 if (!canCoalesceBranch(Cand1))
745 break;
746
747 Cand2.BranchBlock = Cand1.BranchTargetBlock;
748 if (!canCoalesceBranch(Cand2))
749 break;
750
751 // Sanity check
752 // The branch-taken block of the second candidate should post-dominate the
753 // first candidate
754 assert(MPDT->dominates(Cand2.BranchTargetBlock, Cand1.BranchBlock) &&
755 "Branch-taken block should post-dominate first candidate");
756
757 if (!identicalOperands(Cand1.Cond, Cand2.Cond)) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000758 LLVM_DEBUG(dbgs() << "Blocks " << Cand1.BranchBlock->getNumber()
759 << " and " << Cand2.BranchBlock->getNumber()
760 << " have different branches\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000761 break;
762 }
763 if (!canMerge(Cand2, Cand1)) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000764 LLVM_DEBUG(dbgs() << "Cannot merge blocks "
765 << Cand1.BranchBlock->getNumber() << " and "
766 << Cand2.BranchBlock->getNumber() << "\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000767 NumBlocksNotCoalesced++;
768 continue;
769 }
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000770 LLVM_DEBUG(dbgs() << "Merging blocks " << Cand1.BranchBlock->getNumber()
771 << " and " << Cand1.BranchTargetBlock->getNumber()
772 << "\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000773 MergedCandidates = mergeCandidates(Cand2, Cand1);
774 if (MergedCandidates)
775 didSomething = true;
776
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000777 LLVM_DEBUG(dbgs() << "Function after merging: "; MF.dump();
778 dbgs() << "\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000779 } while (MergedCandidates);
780 }
781
782#ifndef NDEBUG
783 // Verify MF is still valid after branch coalescing
784 if (didSomething)
785 MF.verify(nullptr, "Error in code produced by branch coalescing");
786#endif // NDEBUG
787
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000788 LLVM_DEBUG(dbgs() << "Finished Branch Coalescing\n");
Nemanja Ivanovicb223cfa2017-03-01 20:29:34 +0000789 return didSomething;
790}