blob: 77820010cef0276ee98772024031e69c08091739 [file] [log] [blame]
Chris Lattnerf3edc092008-01-04 07:36:53 +00001//===-- MachineSink.cpp - Sinking for machine instructions ----------------===//
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//
Bill Wendling7ee730e2010-06-02 23:04:26 +000010// This pass moves instructions into successor blocks when possible, so that
Dan Gohman5d79a2c2009-08-05 01:19:01 +000011// they aren't executed on paths where their results aren't needed.
12//
13// This pass is not intended to be a replacement or a complete alternative
14// for an LLVM-IR-level sinking pass. It is only designed to sink simple
15// constructs that are not exposed before lowering and instruction selection.
Chris Lattnerf3edc092008-01-04 07:36:53 +000016//
17//===----------------------------------------------------------------------===//
18
Chris Lattnerf3edc092008-01-04 07:36:53 +000019#include "llvm/CodeGen/Passes.h"
Quentin Colombet5cded892014-08-11 23:52:01 +000020#include "llvm/ADT/SetVector.h"
Evan Chenge53ab6d2010-09-17 22:28:18 +000021#include "llvm/ADT/SmallSet.h"
Chris Lattnerf3edc092008-01-04 07:36:53 +000022#include "llvm/ADT/Statistic.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000023#include "llvm/Analysis/AliasAnalysis.h"
24#include "llvm/CodeGen/MachineDominators.h"
25#include "llvm/CodeGen/MachineLoopInfo.h"
Jingyue Wu5208cc52014-09-01 03:47:25 +000026#include "llvm/CodeGen/MachinePostDominators.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000027#include "llvm/CodeGen/MachineRegisterInfo.h"
Evan Chengae9939c2010-08-19 17:33:11 +000028#include "llvm/Support/CommandLine.h"
Chris Lattnerf3edc092008-01-04 07:36:53 +000029#include "llvm/Support/Debug.h"
Bill Wendling63aa0002009-08-22 20:26:23 +000030#include "llvm/Support/raw_ostream.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000031#include "llvm/Target/TargetInstrInfo.h"
32#include "llvm/Target/TargetMachine.h"
33#include "llvm/Target/TargetRegisterInfo.h"
Eric Christopherd9134482014-08-04 21:25:23 +000034#include "llvm/Target/TargetSubtargetInfo.h"
Chris Lattnerf3edc092008-01-04 07:36:53 +000035using namespace llvm;
36
Chandler Carruth1b9dde02014-04-22 02:02:50 +000037#define DEBUG_TYPE "machine-sink"
38
Andrew Trick9e761992012-02-08 21:22:43 +000039static cl::opt<bool>
Evan Chengae9939c2010-08-19 17:33:11 +000040SplitEdges("machine-sink-split",
41 cl::desc("Split critical edges during machine sinking"),
Evan Chengf3e9a482010-09-20 22:52:00 +000042 cl::init(true), cl::Hidden);
Evan Chengae9939c2010-08-19 17:33:11 +000043
Evan Chenge53ab6d2010-09-17 22:28:18 +000044STATISTIC(NumSunk, "Number of machine instructions sunk");
45STATISTIC(NumSplit, "Number of critical edges split");
46STATISTIC(NumCoalesces, "Number of copies coalesced");
Chris Lattnerf3edc092008-01-04 07:36:53 +000047
48namespace {
Nick Lewycky02d5f772009-10-25 06:33:48 +000049 class MachineSinking : public MachineFunctionPass {
Chris Lattnerf3edc092008-01-04 07:36:53 +000050 const TargetInstrInfo *TII;
Dan Gohmana3176872009-09-25 22:53:29 +000051 const TargetRegisterInfo *TRI;
Jingyue Wu5208cc52014-09-01 03:47:25 +000052 MachineRegisterInfo *MRI; // Machine register information
53 MachineDominatorTree *DT; // Machine dominator tree
54 MachinePostDominatorTree *PDT; // Machine post dominator tree
Jakob Stoklund Olesencdc3df42010-04-15 23:41:02 +000055 MachineLoopInfo *LI;
Dan Gohman87b02d52009-10-09 23:27:56 +000056 AliasAnalysis *AA;
Chris Lattnerf3edc092008-01-04 07:36:53 +000057
Evan Chenge53ab6d2010-09-17 22:28:18 +000058 // Remember which edges have been considered for breaking.
59 SmallSet<std::pair<MachineBasicBlock*,MachineBasicBlock*>, 8>
60 CEBCandidates;
Quentin Colombet5cded892014-08-11 23:52:01 +000061 // Remember which edges we are about to split.
62 // This is different from CEBCandidates since those edges
63 // will be split.
64 SetVector<std::pair<MachineBasicBlock*,MachineBasicBlock*> > ToSplit;
Evan Chenge53ab6d2010-09-17 22:28:18 +000065
Chris Lattnerf3edc092008-01-04 07:36:53 +000066 public:
67 static char ID; // Pass identification
Owen Anderson6c18d1a2010-10-19 17:21:58 +000068 MachineSinking() : MachineFunctionPass(ID) {
69 initializeMachineSinkingPass(*PassRegistry::getPassRegistry());
70 }
Jim Grosbach01edd682010-06-03 23:49:57 +000071
Craig Topper4584cd52014-03-07 09:26:03 +000072 bool runOnMachineFunction(MachineFunction &MF) override;
Jim Grosbach01edd682010-06-03 23:49:57 +000073
Craig Topper4584cd52014-03-07 09:26:03 +000074 void getAnalysisUsage(AnalysisUsage &AU) const override {
Dan Gohman04023152009-07-31 23:37:33 +000075 AU.setPreservesCFG();
Chris Lattnerf3edc092008-01-04 07:36:53 +000076 MachineFunctionPass::getAnalysisUsage(AU);
Dan Gohman87b02d52009-10-09 23:27:56 +000077 AU.addRequired<AliasAnalysis>();
Chris Lattnerf3edc092008-01-04 07:36:53 +000078 AU.addRequired<MachineDominatorTree>();
Jingyue Wu5208cc52014-09-01 03:47:25 +000079 AU.addRequired<MachinePostDominatorTree>();
Jakob Stoklund Olesencdc3df42010-04-15 23:41:02 +000080 AU.addRequired<MachineLoopInfo>();
Chris Lattnerf3edc092008-01-04 07:36:53 +000081 AU.addPreserved<MachineDominatorTree>();
Jingyue Wu5208cc52014-09-01 03:47:25 +000082 AU.addPreserved<MachinePostDominatorTree>();
Jakob Stoklund Olesencdc3df42010-04-15 23:41:02 +000083 AU.addPreserved<MachineLoopInfo>();
Chris Lattnerf3edc092008-01-04 07:36:53 +000084 }
Evan Chenge53ab6d2010-09-17 22:28:18 +000085
Craig Topper4584cd52014-03-07 09:26:03 +000086 void releaseMemory() override {
Evan Chenge53ab6d2010-09-17 22:28:18 +000087 CEBCandidates.clear();
88 }
89
Chris Lattnerf3edc092008-01-04 07:36:53 +000090 private:
91 bool ProcessBlock(MachineBasicBlock &MBB);
Evan Chenge53ab6d2010-09-17 22:28:18 +000092 bool isWorthBreakingCriticalEdge(MachineInstr *MI,
93 MachineBasicBlock *From,
94 MachineBasicBlock *To);
Quentin Colombet5cded892014-08-11 23:52:01 +000095 /// \brief Postpone the splitting of the given critical
96 /// edge (\p From, \p To).
97 ///
98 /// We do not split the edges on the fly. Indeed, this invalidates
99 /// the dominance information and thus triggers a lot of updates
100 /// of that information underneath.
101 /// Instead, we postpone all the splits after each iteration of
102 /// the main loop. That way, the information is at least valid
103 /// for the lifetime of an iteration.
104 ///
105 /// \return True if the edge is marked as toSplit, false otherwise.
106 /// False can be retruned if, for instance, this is not profitable.
107 bool PostponeSplitCriticalEdge(MachineInstr *MI,
108 MachineBasicBlock *From,
109 MachineBasicBlock *To,
110 bool BreakPHIEdge);
Chris Lattner08af5a92008-01-12 00:17:41 +0000111 bool SinkInstruction(MachineInstr *MI, bool &SawStore);
Evan Cheng25b60682010-08-18 23:09:25 +0000112 bool AllUsesDominatedByBlock(unsigned Reg, MachineBasicBlock *MBB,
Evan Chenge53ab6d2010-09-17 22:28:18 +0000113 MachineBasicBlock *DefMBB,
Evan Cheng2031b762010-09-20 19:12:55 +0000114 bool &BreakPHIEdge, bool &LocalUse) const;
Devang Patelc2686882011-12-14 23:20:38 +0000115 MachineBasicBlock *FindSuccToSinkTo(MachineInstr *MI, MachineBasicBlock *MBB,
116 bool &BreakPHIEdge);
Andrew Trick9e761992012-02-08 21:22:43 +0000117 bool isProfitableToSinkTo(unsigned Reg, MachineInstr *MI,
Devang Patelc2686882011-12-14 23:20:38 +0000118 MachineBasicBlock *MBB,
119 MachineBasicBlock *SuccToSinkTo);
Devang Patelb94c9a42011-12-08 21:48:01 +0000120
Evan Chenge53ab6d2010-09-17 22:28:18 +0000121 bool PerformTrivialForwardCoalescing(MachineInstr *MI,
122 MachineBasicBlock *MBB);
Chris Lattnerf3edc092008-01-04 07:36:53 +0000123 };
Chris Lattnerf3edc092008-01-04 07:36:53 +0000124} // end anonymous namespace
Jim Grosbach01edd682010-06-03 23:49:57 +0000125
Dan Gohmand78c4002008-05-13 00:00:25 +0000126char MachineSinking::ID = 0;
Andrew Trick1fa5bcb2012-02-08 21:23:13 +0000127char &llvm::MachineSinkingID = MachineSinking::ID;
Owen Anderson8ac477f2010-10-12 19:48:12 +0000128INITIALIZE_PASS_BEGIN(MachineSinking, "machine-sink",
129 "Machine code sinking", false, false)
130INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
131INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
132INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
133INITIALIZE_PASS_END(MachineSinking, "machine-sink",
Owen Andersondf7a4f22010-10-07 22:25:06 +0000134 "Machine code sinking", false, false)
Chris Lattnerf3edc092008-01-04 07:36:53 +0000135
Evan Chenge53ab6d2010-09-17 22:28:18 +0000136bool MachineSinking::PerformTrivialForwardCoalescing(MachineInstr *MI,
137 MachineBasicBlock *MBB) {
138 if (!MI->isCopy())
139 return false;
140
141 unsigned SrcReg = MI->getOperand(1).getReg();
142 unsigned DstReg = MI->getOperand(0).getReg();
143 if (!TargetRegisterInfo::isVirtualRegister(SrcReg) ||
144 !TargetRegisterInfo::isVirtualRegister(DstReg) ||
145 !MRI->hasOneNonDBGUse(SrcReg))
146 return false;
147
148 const TargetRegisterClass *SRC = MRI->getRegClass(SrcReg);
149 const TargetRegisterClass *DRC = MRI->getRegClass(DstReg);
150 if (SRC != DRC)
151 return false;
152
153 MachineInstr *DefMI = MRI->getVRegDef(SrcReg);
154 if (DefMI->isCopyLike())
155 return false;
156 DEBUG(dbgs() << "Coalescing: " << *DefMI);
157 DEBUG(dbgs() << "*** to: " << *MI);
158 MRI->replaceRegWith(DstReg, SrcReg);
159 MI->eraseFromParent();
160 ++NumCoalesces;
161 return true;
162}
163
Chris Lattnerf3edc092008-01-04 07:36:53 +0000164/// AllUsesDominatedByBlock - Return true if all uses of the specified register
Evan Cheng25b60682010-08-18 23:09:25 +0000165/// occur in blocks dominated by the specified block. If any use is in the
166/// definition block, then return false since it is never legal to move def
167/// after uses.
Evan Chenge53ab6d2010-09-17 22:28:18 +0000168bool
169MachineSinking::AllUsesDominatedByBlock(unsigned Reg,
170 MachineBasicBlock *MBB,
171 MachineBasicBlock *DefMBB,
Evan Cheng2031b762010-09-20 19:12:55 +0000172 bool &BreakPHIEdge,
173 bool &LocalUse) const {
Dan Gohman3a4be0f2008-02-10 18:45:23 +0000174 assert(TargetRegisterInfo::isVirtualRegister(Reg) &&
175 "Only makes sense for vregs");
Evan Chengb339f3d2010-09-18 06:42:17 +0000176
Devang Patel706574a2011-12-09 01:25:04 +0000177 // Ignore debug uses because debug info doesn't affect the code.
Evan Chengb339f3d2010-09-18 06:42:17 +0000178 if (MRI->use_nodbg_empty(Reg))
179 return true;
180
Evan Cheng2031b762010-09-20 19:12:55 +0000181 // BreakPHIEdge is true if all the uses are in the successor MBB being sunken
182 // into and they are all PHI nodes. In this case, machine-sink must break
183 // the critical edge first. e.g.
184 //
Evan Chengb339f3d2010-09-18 06:42:17 +0000185 // BB#1: derived from LLVM BB %bb4.preheader
186 // Predecessors according to CFG: BB#0
187 // ...
188 // %reg16385<def> = DEC64_32r %reg16437, %EFLAGS<imp-def,dead>
189 // ...
190 // JE_4 <BB#37>, %EFLAGS<imp-use>
191 // Successors according to CFG: BB#37 BB#2
192 //
193 // BB#2: derived from LLVM BB %bb.nph
194 // Predecessors according to CFG: BB#0 BB#1
195 // %reg16386<def> = PHI %reg16434, <BB#0>, %reg16385, <BB#1>
Evan Cheng2031b762010-09-20 19:12:55 +0000196 BreakPHIEdge = true;
Owen Andersonb36376e2014-03-17 19:36:09 +0000197 for (MachineOperand &MO : MRI->use_nodbg_operands(Reg)) {
198 MachineInstr *UseInst = MO.getParent();
199 unsigned OpNo = &MO - &UseInst->getOperand(0);
Evan Chengb339f3d2010-09-18 06:42:17 +0000200 MachineBasicBlock *UseBlock = UseInst->getParent();
201 if (!(UseBlock == MBB && UseInst->isPHI() &&
Owen Andersonb36376e2014-03-17 19:36:09 +0000202 UseInst->getOperand(OpNo+1).getMBB() == DefMBB)) {
Evan Cheng2031b762010-09-20 19:12:55 +0000203 BreakPHIEdge = false;
Evan Chengb339f3d2010-09-18 06:42:17 +0000204 break;
205 }
206 }
Evan Cheng2031b762010-09-20 19:12:55 +0000207 if (BreakPHIEdge)
Evan Chengb339f3d2010-09-18 06:42:17 +0000208 return true;
209
Owen Andersonb36376e2014-03-17 19:36:09 +0000210 for (MachineOperand &MO : MRI->use_nodbg_operands(Reg)) {
Chris Lattnerf3edc092008-01-04 07:36:53 +0000211 // Determine the block of the use.
Owen Andersonb36376e2014-03-17 19:36:09 +0000212 MachineInstr *UseInst = MO.getParent();
213 unsigned OpNo = &MO - &UseInst->getOperand(0);
Chris Lattnerf3edc092008-01-04 07:36:53 +0000214 MachineBasicBlock *UseBlock = UseInst->getParent();
Evan Chengb339f3d2010-09-18 06:42:17 +0000215 if (UseInst->isPHI()) {
Chris Lattnerf3edc092008-01-04 07:36:53 +0000216 // PHI nodes use the operand in the predecessor block, not the block with
217 // the PHI.
Owen Andersonb36376e2014-03-17 19:36:09 +0000218 UseBlock = UseInst->getOperand(OpNo+1).getMBB();
Evan Cheng361b9be2010-08-19 18:33:29 +0000219 } else if (UseBlock == DefMBB) {
220 LocalUse = true;
221 return false;
Chris Lattnerf3edc092008-01-04 07:36:53 +0000222 }
Bill Wendling7ee730e2010-06-02 23:04:26 +0000223
Chris Lattnerf3edc092008-01-04 07:36:53 +0000224 // Check that it dominates.
225 if (!DT->dominates(MBB, UseBlock))
226 return false;
227 }
Bill Wendling7ee730e2010-06-02 23:04:26 +0000228
Chris Lattnerf3edc092008-01-04 07:36:53 +0000229 return true;
230}
231
Chris Lattnerf3edc092008-01-04 07:36:53 +0000232bool MachineSinking::runOnMachineFunction(MachineFunction &MF) {
Paul Robinson7c99ec52014-03-31 17:43:35 +0000233 if (skipOptnoneFunction(*MF.getFunction()))
234 return false;
235
David Greene4b7aa242010-01-05 01:26:00 +0000236 DEBUG(dbgs() << "******** Machine Sinking ********\n");
Jim Grosbach01edd682010-06-03 23:49:57 +0000237
Dan Gohman20a327b2009-10-19 14:52:05 +0000238 const TargetMachine &TM = MF.getTarget();
Eric Christopherd9134482014-08-04 21:25:23 +0000239 TII = TM.getSubtargetImpl()->getInstrInfo();
240 TRI = TM.getSubtargetImpl()->getRegisterInfo();
Evan Chenge53ab6d2010-09-17 22:28:18 +0000241 MRI = &MF.getRegInfo();
Chris Lattnerf3edc092008-01-04 07:36:53 +0000242 DT = &getAnalysis<MachineDominatorTree>();
Jingyue Wu5208cc52014-09-01 03:47:25 +0000243 PDT = &getAnalysis<MachinePostDominatorTree>();
Jakob Stoklund Olesencdc3df42010-04-15 23:41:02 +0000244 LI = &getAnalysis<MachineLoopInfo>();
Dan Gohman87b02d52009-10-09 23:27:56 +0000245 AA = &getAnalysis<AliasAnalysis>();
Chris Lattnerf3edc092008-01-04 07:36:53 +0000246
247 bool EverMadeChange = false;
Jim Grosbach01edd682010-06-03 23:49:57 +0000248
Chris Lattnerf3edc092008-01-04 07:36:53 +0000249 while (1) {
250 bool MadeChange = false;
251
252 // Process all basic blocks.
Evan Chenge53ab6d2010-09-17 22:28:18 +0000253 CEBCandidates.clear();
Quentin Colombet5cded892014-08-11 23:52:01 +0000254 ToSplit.clear();
Jim Grosbach01edd682010-06-03 23:49:57 +0000255 for (MachineFunction::iterator I = MF.begin(), E = MF.end();
Chris Lattnerf3edc092008-01-04 07:36:53 +0000256 I != E; ++I)
257 MadeChange |= ProcessBlock(*I);
Jim Grosbach01edd682010-06-03 23:49:57 +0000258
Quentin Colombet5cded892014-08-11 23:52:01 +0000259 // If we have anything we marked as toSplit, split it now.
260 for (auto &Pair : ToSplit) {
261 auto NewSucc = Pair.first->SplitCriticalEdge(Pair.second, this);
262 if (NewSucc != nullptr) {
263 DEBUG(dbgs() << " *** Splitting critical edge:"
264 " BB#" << Pair.first->getNumber()
265 << " -- BB#" << NewSucc->getNumber()
266 << " -- BB#" << Pair.second->getNumber() << '\n');
267 MadeChange = true;
268 ++NumSplit;
269 } else
270 DEBUG(dbgs() << " *** Not legal to break critical edge\n");
271 }
Chris Lattnerf3edc092008-01-04 07:36:53 +0000272 // If this iteration over the code changed anything, keep iterating.
273 if (!MadeChange) break;
274 EverMadeChange = true;
Jim Grosbach01edd682010-06-03 23:49:57 +0000275 }
Chris Lattnerf3edc092008-01-04 07:36:53 +0000276 return EverMadeChange;
277}
278
279bool MachineSinking::ProcessBlock(MachineBasicBlock &MBB) {
Chris Lattnerf3edc092008-01-04 07:36:53 +0000280 // Can't sink anything out of a block that has less than two successors.
Chris Lattner30c3de62009-04-10 16:38:36 +0000281 if (MBB.succ_size() <= 1 || MBB.empty()) return false;
282
Dan Gohman918a90a2010-04-05 19:17:22 +0000283 // Don't bother sinking code out of unreachable blocks. In addition to being
Jim Grosbach01edd682010-06-03 23:49:57 +0000284 // unprofitable, it can also lead to infinite looping, because in an
285 // unreachable loop there may be nowhere to stop.
Dan Gohman918a90a2010-04-05 19:17:22 +0000286 if (!DT->isReachableFromEntry(&MBB)) return false;
287
Chris Lattner30c3de62009-04-10 16:38:36 +0000288 bool MadeChange = false;
289
Chris Lattner08af5a92008-01-12 00:17:41 +0000290 // Walk the basic block bottom-up. Remember if we saw a store.
Chris Lattner30c3de62009-04-10 16:38:36 +0000291 MachineBasicBlock::iterator I = MBB.end();
292 --I;
293 bool ProcessedBegin, SawStore = false;
294 do {
295 MachineInstr *MI = I; // The instruction to sink.
Jim Grosbach01edd682010-06-03 23:49:57 +0000296
Chris Lattner30c3de62009-04-10 16:38:36 +0000297 // Predecrement I (if it's not begin) so that it isn't invalidated by
298 // sinking.
299 ProcessedBegin = I == MBB.begin();
300 if (!ProcessedBegin)
301 --I;
Dale Johannesen2061c842010-03-05 00:02:59 +0000302
303 if (MI->isDebugValue())
304 continue;
305
Evan Chengfe917ef2011-04-11 18:47:20 +0000306 bool Joined = PerformTrivialForwardCoalescing(MI, &MBB);
307 if (Joined) {
308 MadeChange = true;
Evan Chenge53ab6d2010-09-17 22:28:18 +0000309 continue;
Evan Chengfe917ef2011-04-11 18:47:20 +0000310 }
Evan Chenge53ab6d2010-09-17 22:28:18 +0000311
Chris Lattner30c3de62009-04-10 16:38:36 +0000312 if (SinkInstruction(MI, SawStore))
313 ++NumSunk, MadeChange = true;
Jim Grosbach01edd682010-06-03 23:49:57 +0000314
Chris Lattner30c3de62009-04-10 16:38:36 +0000315 // If we just processed the first instruction in the block, we're done.
316 } while (!ProcessedBegin);
Jim Grosbach01edd682010-06-03 23:49:57 +0000317
Chris Lattnerf3edc092008-01-04 07:36:53 +0000318 return MadeChange;
319}
320
Evan Chenge53ab6d2010-09-17 22:28:18 +0000321bool MachineSinking::isWorthBreakingCriticalEdge(MachineInstr *MI,
322 MachineBasicBlock *From,
323 MachineBasicBlock *To) {
324 // FIXME: Need much better heuristics.
325
326 // If the pass has already considered breaking this edge (during this pass
327 // through the function), then let's go ahead and break it. This means
328 // sinking multiple "cheap" instructions into the same block.
329 if (!CEBCandidates.insert(std::make_pair(From, To)))
330 return true;
331
Jiangning Liuc3053122014-07-29 01:55:19 +0000332 if (!MI->isCopy() && !TII->isAsCheapAsAMove(MI))
Evan Chenge53ab6d2010-09-17 22:28:18 +0000333 return true;
334
335 // MI is cheap, we probably don't want to break the critical edge for it.
336 // However, if this would allow some definitions of its source operands
337 // to be sunk then it's probably worth it.
338 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
339 const MachineOperand &MO = MI->getOperand(i);
Will Dietz5cb7f4e2013-10-14 16:57:17 +0000340 if (!MO.isReg() || !MO.isUse())
Evan Chenge53ab6d2010-09-17 22:28:18 +0000341 continue;
Will Dietz5cb7f4e2013-10-14 16:57:17 +0000342 unsigned Reg = MO.getReg();
343 if (Reg == 0)
344 continue;
345
346 // We don't move live definitions of physical registers,
347 // so sinking their uses won't enable any opportunities.
348 if (TargetRegisterInfo::isPhysicalRegister(Reg))
349 continue;
350
351 // If this instruction is the only user of a virtual register,
352 // check if breaking the edge will enable sinking
353 // both this instruction and the defining instruction.
354 if (MRI->hasOneNonDBGUse(Reg)) {
355 // If the definition resides in same MBB,
356 // claim it's likely we can sink these together.
357 // If definition resides elsewhere, we aren't
358 // blocking it from being sunk so don't break the edge.
359 MachineInstr *DefMI = MRI->getVRegDef(Reg);
360 if (DefMI->getParent() == MI->getParent())
361 return true;
362 }
Evan Chenge53ab6d2010-09-17 22:28:18 +0000363 }
364
365 return false;
366}
367
Quentin Colombet5cded892014-08-11 23:52:01 +0000368bool MachineSinking::PostponeSplitCriticalEdge(MachineInstr *MI,
369 MachineBasicBlock *FromBB,
370 MachineBasicBlock *ToBB,
371 bool BreakPHIEdge) {
Evan Chenge53ab6d2010-09-17 22:28:18 +0000372 if (!isWorthBreakingCriticalEdge(MI, FromBB, ToBB))
Quentin Colombet5cded892014-08-11 23:52:01 +0000373 return false;
Evan Chenge53ab6d2010-09-17 22:28:18 +0000374
Evan Chengae9939c2010-08-19 17:33:11 +0000375 // Avoid breaking back edge. From == To means backedge for single BB loop.
Evan Chengf3e9a482010-09-20 22:52:00 +0000376 if (!SplitEdges || FromBB == ToBB)
Quentin Colombet5cded892014-08-11 23:52:01 +0000377 return false;
Evan Chengae9939c2010-08-19 17:33:11 +0000378
Evan Chenge53ab6d2010-09-17 22:28:18 +0000379 // Check for backedges of more "complex" loops.
380 if (LI->getLoopFor(FromBB) == LI->getLoopFor(ToBB) &&
381 LI->isLoopHeader(ToBB))
Quentin Colombet5cded892014-08-11 23:52:01 +0000382 return false;
Evan Chenge53ab6d2010-09-17 22:28:18 +0000383
384 // It's not always legal to break critical edges and sink the computation
385 // to the edge.
386 //
387 // BB#1:
388 // v1024
389 // Beq BB#3
390 // <fallthrough>
391 // BB#2:
392 // ... no uses of v1024
393 // <fallthrough>
394 // BB#3:
395 // ...
396 // = v1024
397 //
398 // If BB#1 -> BB#3 edge is broken and computation of v1024 is inserted:
399 //
400 // BB#1:
401 // ...
402 // Bne BB#2
403 // BB#4:
404 // v1024 =
405 // B BB#3
406 // BB#2:
407 // ... no uses of v1024
408 // <fallthrough>
409 // BB#3:
410 // ...
411 // = v1024
412 //
413 // This is incorrect since v1024 is not computed along the BB#1->BB#2->BB#3
414 // flow. We need to ensure the new basic block where the computation is
415 // sunk to dominates all the uses.
416 // It's only legal to break critical edge and sink the computation to the
417 // new block if all the predecessors of "To", except for "From", are
418 // not dominated by "From". Given SSA property, this means these
419 // predecessors are dominated by "To".
420 //
421 // There is no need to do this check if all the uses are PHI nodes. PHI
422 // sources are only defined on the specific predecessor edges.
Evan Cheng2031b762010-09-20 19:12:55 +0000423 if (!BreakPHIEdge) {
Evan Chengae9939c2010-08-19 17:33:11 +0000424 for (MachineBasicBlock::pred_iterator PI = ToBB->pred_begin(),
425 E = ToBB->pred_end(); PI != E; ++PI) {
426 if (*PI == FromBB)
427 continue;
428 if (!DT->dominates(ToBB, *PI))
Quentin Colombet5cded892014-08-11 23:52:01 +0000429 return false;
Evan Chengae9939c2010-08-19 17:33:11 +0000430 }
Evan Chengae9939c2010-08-19 17:33:11 +0000431 }
432
Quentin Colombet5cded892014-08-11 23:52:01 +0000433 ToSplit.insert(std::make_pair(FromBB, ToBB));
434
435 return true;
Evan Chengae9939c2010-08-19 17:33:11 +0000436}
437
Evan Chengd4b31a72010-09-23 06:53:00 +0000438static bool AvoidsSinking(MachineInstr *MI, MachineRegisterInfo *MRI) {
439 return MI->isInsertSubreg() || MI->isSubregToReg() || MI->isRegSequence();
440}
441
Andrew Trick9e761992012-02-08 21:22:43 +0000442/// collectDebgValues - Scan instructions following MI and collect any
Devang Patel9de7a7d2011-09-07 00:07:58 +0000443/// matching DBG_VALUEs.
Andrew Trick9e761992012-02-08 21:22:43 +0000444static void collectDebugValues(MachineInstr *MI,
Craig Topperb94011f2013-07-14 04:42:23 +0000445 SmallVectorImpl<MachineInstr *> &DbgValues) {
Devang Patel9de7a7d2011-09-07 00:07:58 +0000446 DbgValues.clear();
447 if (!MI->getOperand(0).isReg())
448 return;
449
450 MachineBasicBlock::iterator DI = MI; ++DI;
451 for (MachineBasicBlock::iterator DE = MI->getParent()->end();
452 DI != DE; ++DI) {
453 if (!DI->isDebugValue())
454 return;
455 if (DI->getOperand(0).isReg() &&
456 DI->getOperand(0).getReg() == MI->getOperand(0).getReg())
457 DbgValues.push_back(DI);
458 }
459}
460
Devang Patelc2686882011-12-14 23:20:38 +0000461/// isProfitableToSinkTo - Return true if it is profitable to sink MI.
Andrew Trick9e761992012-02-08 21:22:43 +0000462bool MachineSinking::isProfitableToSinkTo(unsigned Reg, MachineInstr *MI,
Devang Patelc2686882011-12-14 23:20:38 +0000463 MachineBasicBlock *MBB,
464 MachineBasicBlock *SuccToSinkTo) {
465 assert (MI && "Invalid MachineInstr!");
466 assert (SuccToSinkTo && "Invalid SinkTo Candidate BB");
467
468 if (MBB == SuccToSinkTo)
469 return false;
470
471 // It is profitable if SuccToSinkTo does not post dominate current block.
Jingyue Wu5208cc52014-09-01 03:47:25 +0000472 if (!PDT->dominates(SuccToSinkTo, MBB))
473 return true;
Devang Patelc2686882011-12-14 23:20:38 +0000474
475 // Check if only use in post dominated block is PHI instruction.
476 bool NonPHIUse = false;
Owen Andersonb36376e2014-03-17 19:36:09 +0000477 for (MachineInstr &UseInst : MRI->use_nodbg_instructions(Reg)) {
478 MachineBasicBlock *UseBlock = UseInst.getParent();
479 if (UseBlock == SuccToSinkTo && !UseInst.isPHI())
Devang Patelc2686882011-12-14 23:20:38 +0000480 NonPHIUse = true;
481 }
482 if (!NonPHIUse)
483 return true;
484
485 // If SuccToSinkTo post dominates then also it may be profitable if MI
486 // can further profitably sinked into another block in next round.
487 bool BreakPHIEdge = false;
488 // FIXME - If finding successor is compile time expensive then catch results.
489 if (MachineBasicBlock *MBB2 = FindSuccToSinkTo(MI, SuccToSinkTo, BreakPHIEdge))
490 return isProfitableToSinkTo(Reg, MI, SuccToSinkTo, MBB2);
491
492 // If SuccToSinkTo is final destination and it is a post dominator of current
493 // block then it is not profitable to sink MI into SuccToSinkTo block.
494 return false;
495}
496
Devang Patelb94c9a42011-12-08 21:48:01 +0000497/// FindSuccToSinkTo - Find a successor to sink this instruction to.
498MachineBasicBlock *MachineSinking::FindSuccToSinkTo(MachineInstr *MI,
Devang Patelc2686882011-12-14 23:20:38 +0000499 MachineBasicBlock *MBB,
500 bool &BreakPHIEdge) {
501
502 assert (MI && "Invalid MachineInstr!");
503 assert (MBB && "Invalid MachineBasicBlock!");
Jim Grosbach01edd682010-06-03 23:49:57 +0000504
Chris Lattnerf3edc092008-01-04 07:36:53 +0000505 // Loop over all the operands of the specified instruction. If there is
506 // anything we can't handle, bail out.
Jim Grosbach01edd682010-06-03 23:49:57 +0000507
Chris Lattnerf3edc092008-01-04 07:36:53 +0000508 // SuccToSinkTo - This is the successor to sink this instruction to, once we
509 // decide.
Craig Topperc0196b12014-04-14 00:51:57 +0000510 MachineBasicBlock *SuccToSinkTo = nullptr;
Chris Lattnerf3edc092008-01-04 07:36:53 +0000511 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
512 const MachineOperand &MO = MI->getOperand(i);
Dan Gohman0d1e9a82008-10-03 15:45:36 +0000513 if (!MO.isReg()) continue; // Ignore non-register operands.
Jim Grosbach01edd682010-06-03 23:49:57 +0000514
Chris Lattnerf3edc092008-01-04 07:36:53 +0000515 unsigned Reg = MO.getReg();
516 if (Reg == 0) continue;
Jim Grosbach01edd682010-06-03 23:49:57 +0000517
Dan Gohman3a4be0f2008-02-10 18:45:23 +0000518 if (TargetRegisterInfo::isPhysicalRegister(Reg)) {
Dan Gohmana3176872009-09-25 22:53:29 +0000519 if (MO.isUse()) {
520 // If the physreg has no defs anywhere, it's just an ambient register
Dan Gohman2f5bdcb2009-09-26 02:34:00 +0000521 // and we can freely move its uses. Alternatively, if it's allocatable,
522 // it could get allocated to something with a def during allocation.
Jakob Stoklund Olesen86ae07f2012-01-16 22:34:08 +0000523 if (!MRI->isConstantPhysReg(Reg, *MBB->getParent()))
Craig Topperc0196b12014-04-14 00:51:57 +0000524 return nullptr;
Bill Wendlinge41e40f2010-06-25 20:48:10 +0000525 } else if (!MO.isDead()) {
526 // A def that isn't dead. We can't move it.
Craig Topperc0196b12014-04-14 00:51:57 +0000527 return nullptr;
Dan Gohmana3176872009-09-25 22:53:29 +0000528 }
Chris Lattnerf3edc092008-01-04 07:36:53 +0000529 } else {
530 // Virtual register uses are always safe to sink.
531 if (MO.isUse()) continue;
Evan Cheng47a65a12009-02-07 01:21:47 +0000532
533 // If it's not safe to move defs of the register class, then abort.
Evan Chenge53ab6d2010-09-17 22:28:18 +0000534 if (!TII->isSafeToMoveRegClassDefs(MRI->getRegClass(Reg)))
Craig Topperc0196b12014-04-14 00:51:57 +0000535 return nullptr;
Jim Grosbach01edd682010-06-03 23:49:57 +0000536
Chris Lattneree61d142008-01-05 06:47:58 +0000537 // FIXME: This picks a successor to sink into based on having one
538 // successor that dominates all the uses. However, there are cases where
539 // sinking can happen but where the sink point isn't a successor. For
540 // example:
Jim Grosbach01edd682010-06-03 23:49:57 +0000541 //
Chris Lattneree61d142008-01-05 06:47:58 +0000542 // x = computation
543 // if () {} else {}
544 // use x
Jim Grosbach01edd682010-06-03 23:49:57 +0000545 //
Bill Wendling7ee730e2010-06-02 23:04:26 +0000546 // the instruction could be sunk over the whole diamond for the
Chris Lattneree61d142008-01-05 06:47:58 +0000547 // if/then/else (or loop, etc), allowing it to be sunk into other blocks
548 // after that.
Jim Grosbach01edd682010-06-03 23:49:57 +0000549
Chris Lattnerf3edc092008-01-04 07:36:53 +0000550 // Virtual register defs can only be sunk if all their uses are in blocks
551 // dominated by one of the successors.
552 if (SuccToSinkTo) {
553 // If a previous operand picked a block to sink to, then this operand
554 // must be sinkable to the same block.
Evan Cheng361b9be2010-08-19 18:33:29 +0000555 bool LocalUse = false;
Devang Patelc2686882011-12-14 23:20:38 +0000556 if (!AllUsesDominatedByBlock(Reg, SuccToSinkTo, MBB,
Evan Cheng2031b762010-09-20 19:12:55 +0000557 BreakPHIEdge, LocalUse))
Craig Topperc0196b12014-04-14 00:51:57 +0000558 return nullptr;
Bill Wendling7ee730e2010-06-02 23:04:26 +0000559
Chris Lattnerf3edc092008-01-04 07:36:53 +0000560 continue;
561 }
Jim Grosbach01edd682010-06-03 23:49:57 +0000562
Chris Lattnerf3edc092008-01-04 07:36:53 +0000563 // Otherwise, we should look at all the successors and decide which one
564 // we should sink to.
Manman Ren8c549b52012-07-31 18:10:39 +0000565 // We give successors with smaller loop depth higher priority.
566 SmallVector<MachineBasicBlock*, 4> Succs(MBB->succ_begin(), MBB->succ_end());
Benjamin Kramer3a377bc2014-03-01 11:47:00 +0000567 // Sort Successors according to their loop depth.
568 std::stable_sort(
569 Succs.begin(), Succs.end(),
570 [this](const MachineBasicBlock *LHS, const MachineBasicBlock *RHS) {
571 return LI->getLoopDepth(LHS) < LI->getLoopDepth(RHS);
572 });
Craig Toppere1c1d362013-07-03 05:11:49 +0000573 for (SmallVectorImpl<MachineBasicBlock *>::iterator SI = Succs.begin(),
574 E = Succs.end(); SI != E; ++SI) {
Devang Patelc2686882011-12-14 23:20:38 +0000575 MachineBasicBlock *SuccBlock = *SI;
Evan Cheng361b9be2010-08-19 18:33:29 +0000576 bool LocalUse = false;
Devang Patelc2686882011-12-14 23:20:38 +0000577 if (AllUsesDominatedByBlock(Reg, SuccBlock, MBB,
Evan Cheng2031b762010-09-20 19:12:55 +0000578 BreakPHIEdge, LocalUse)) {
Devang Patel1a3c1692011-12-08 21:33:23 +0000579 SuccToSinkTo = SuccBlock;
Chris Lattnerf3edc092008-01-04 07:36:53 +0000580 break;
581 }
Evan Cheng25b60682010-08-18 23:09:25 +0000582 if (LocalUse)
583 // Def is used locally, it's never safe to move this def.
Craig Topperc0196b12014-04-14 00:51:57 +0000584 return nullptr;
Chris Lattnerf3edc092008-01-04 07:36:53 +0000585 }
Jim Grosbach01edd682010-06-03 23:49:57 +0000586
Chris Lattnerf3edc092008-01-04 07:36:53 +0000587 // If we couldn't find a block to sink to, ignore this instruction.
Craig Topperc0196b12014-04-14 00:51:57 +0000588 if (!SuccToSinkTo)
589 return nullptr;
590 if (!isProfitableToSinkTo(Reg, MI, MBB, SuccToSinkTo))
591 return nullptr;
Chris Lattnerf3edc092008-01-04 07:36:53 +0000592 }
593 }
Devang Patel202cf2f2011-12-08 23:52:00 +0000594
595 // It is not possible to sink an instruction into its own block. This can
596 // happen with loops.
Devang Patelc2686882011-12-14 23:20:38 +0000597 if (MBB == SuccToSinkTo)
Craig Topperc0196b12014-04-14 00:51:57 +0000598 return nullptr;
Devang Patel202cf2f2011-12-08 23:52:00 +0000599
600 // It's not safe to sink instructions to EH landing pad. Control flow into
601 // landing pad is implicitly defined.
602 if (SuccToSinkTo && SuccToSinkTo->isLandingPad())
Craig Topperc0196b12014-04-14 00:51:57 +0000603 return nullptr;
Devang Patel202cf2f2011-12-08 23:52:00 +0000604
Devang Patelb94c9a42011-12-08 21:48:01 +0000605 return SuccToSinkTo;
606}
607
608/// SinkInstruction - Determine whether it is safe to sink the specified machine
609/// instruction out of its current block into a successor.
610bool MachineSinking::SinkInstruction(MachineInstr *MI, bool &SawStore) {
611 // Don't sink insert_subreg, subreg_to_reg, reg_sequence. These are meant to
612 // be close to the source to make it easier to coalesce.
613 if (AvoidsSinking(MI, MRI))
614 return false;
615
616 // Check if it's safe to move the instruction.
617 if (!MI->isSafeToMove(TII, AA, SawStore))
618 return false;
619
620 // FIXME: This should include support for sinking instructions within the
621 // block they are currently in to shorten the live ranges. We often get
622 // instructions sunk into the top of a large block, but it would be better to
623 // also sink them down before their first use in the block. This xform has to
624 // be careful not to *increase* register pressure though, e.g. sinking
625 // "x = y + z" down if it kills y and z would increase the live ranges of y
626 // and z and only shrink the live range of x.
627
628 bool BreakPHIEdge = false;
Devang Patelc2686882011-12-14 23:20:38 +0000629 MachineBasicBlock *ParentBlock = MI->getParent();
630 MachineBasicBlock *SuccToSinkTo = FindSuccToSinkTo(MI, ParentBlock, BreakPHIEdge);
Jim Grosbach01edd682010-06-03 23:49:57 +0000631
Chris Lattner6ec78272008-01-05 01:39:17 +0000632 // If there are no outputs, it must have side-effects.
Craig Topperc0196b12014-04-14 00:51:57 +0000633 if (!SuccToSinkTo)
Chris Lattner6ec78272008-01-05 01:39:17 +0000634 return false;
Evan Cheng25104362009-02-15 08:36:12 +0000635
Bill Wendlingf82aea62010-06-03 07:54:20 +0000636
Daniel Dunbaref5a4382010-06-23 00:48:25 +0000637 // If the instruction to move defines a dead physical register which is live
638 // when leaving the basic block, don't move it because it could turn into a
639 // "zombie" define of that preg. E.g., EFLAGS. (<rdar://problem/8030636>)
Bill Wendlinge41e40f2010-06-25 20:48:10 +0000640 for (unsigned I = 0, E = MI->getNumOperands(); I != E; ++I) {
641 const MachineOperand &MO = MI->getOperand(I);
642 if (!MO.isReg()) continue;
643 unsigned Reg = MO.getReg();
644 if (Reg == 0 || !TargetRegisterInfo::isPhysicalRegister(Reg)) continue;
645 if (SuccToSinkTo->isLiveIn(Reg))
Bill Wendlingf82aea62010-06-03 07:54:20 +0000646 return false;
Bill Wendlinge41e40f2010-06-25 20:48:10 +0000647 }
Bill Wendlingf82aea62010-06-03 07:54:20 +0000648
Bill Wendling7ee730e2010-06-02 23:04:26 +0000649 DEBUG(dbgs() << "Sink instr " << *MI << "\tinto block " << *SuccToSinkTo);
650
Will Dietz5cb7f4e2013-10-14 16:57:17 +0000651 // If the block has multiple predecessors, this is a critical edge.
652 // Decide if we can sink along it or need to break the edge.
Chris Lattnerf3edc092008-01-04 07:36:53 +0000653 if (SuccToSinkTo->pred_size() > 1) {
Jakob Stoklund Olesen20b71e22010-04-13 19:06:14 +0000654 // We cannot sink a load across a critical edge - there may be stores in
655 // other code paths.
Evan Chengae9939c2010-08-19 17:33:11 +0000656 bool TryBreak = false;
Jakob Stoklund Olesen20b71e22010-04-13 19:06:14 +0000657 bool store = true;
658 if (!MI->isSafeToMove(TII, AA, store)) {
Evan Chenge5af9302010-08-19 23:33:02 +0000659 DEBUG(dbgs() << " *** NOTE: Won't sink load along critical edge.\n");
Evan Chengae9939c2010-08-19 17:33:11 +0000660 TryBreak = true;
Jakob Stoklund Olesen20b71e22010-04-13 19:06:14 +0000661 }
662
663 // We don't want to sink across a critical edge if we don't dominate the
664 // successor. We could be introducing calculations to new code paths.
Evan Chengae9939c2010-08-19 17:33:11 +0000665 if (!TryBreak && !DT->dominates(ParentBlock, SuccToSinkTo)) {
Evan Chenge5af9302010-08-19 23:33:02 +0000666 DEBUG(dbgs() << " *** NOTE: Critical edge found\n");
Evan Chengae9939c2010-08-19 17:33:11 +0000667 TryBreak = true;
Jakob Stoklund Olesen20b71e22010-04-13 19:06:14 +0000668 }
669
Jakob Stoklund Olesencdc3df42010-04-15 23:41:02 +0000670 // Don't sink instructions into a loop.
Evan Chengae9939c2010-08-19 17:33:11 +0000671 if (!TryBreak && LI->isLoopHeader(SuccToSinkTo)) {
Evan Chenge5af9302010-08-19 23:33:02 +0000672 DEBUG(dbgs() << " *** NOTE: Loop header found\n");
Evan Chengae9939c2010-08-19 17:33:11 +0000673 TryBreak = true;
Jakob Stoklund Olesencdc3df42010-04-15 23:41:02 +0000674 }
675
Jakob Stoklund Olesen20b71e22010-04-13 19:06:14 +0000676 // Otherwise we are OK with sinking along a critical edge.
Evan Chengae9939c2010-08-19 17:33:11 +0000677 if (!TryBreak)
678 DEBUG(dbgs() << "Sinking along critical edge.\n");
679 else {
Quentin Colombet5cded892014-08-11 23:52:01 +0000680 // Mark this edge as to be split.
681 // If the edge can actually be split, the next iteration of the main loop
682 // will sink MI in the newly created block.
683 bool Status =
684 PostponeSplitCriticalEdge(MI, ParentBlock, SuccToSinkTo, BreakPHIEdge);
685 if (!Status)
Evan Chenge53ab6d2010-09-17 22:28:18 +0000686 DEBUG(dbgs() << " *** PUNTING: Not legal or profitable to "
Quentin Colombet5cded892014-08-11 23:52:01 +0000687 "break critical edge\n");
688 // The instruction will not be sunk this time.
689 return false;
Evan Chengae9939c2010-08-19 17:33:11 +0000690 }
Chris Lattnerf3edc092008-01-04 07:36:53 +0000691 }
Jim Grosbach01edd682010-06-03 23:49:57 +0000692
Evan Cheng2031b762010-09-20 19:12:55 +0000693 if (BreakPHIEdge) {
694 // BreakPHIEdge is true if all the uses are in the successor MBB being
695 // sunken into and they are all PHI nodes. In this case, machine-sink must
696 // break the critical edge first.
Quentin Colombet5cded892014-08-11 23:52:01 +0000697 bool Status = PostponeSplitCriticalEdge(MI, ParentBlock,
698 SuccToSinkTo, BreakPHIEdge);
699 if (!Status)
Evan Chengb339f3d2010-09-18 06:42:17 +0000700 DEBUG(dbgs() << " *** PUNTING: Not legal or profitable to "
701 "break critical edge\n");
Quentin Colombet5cded892014-08-11 23:52:01 +0000702 // The instruction will not be sunk this time.
703 return false;
Evan Chengb339f3d2010-09-18 06:42:17 +0000704 }
705
Bill Wendling7ee730e2010-06-02 23:04:26 +0000706 // Determine where to insert into. Skip phi nodes.
Chris Lattnerf3edc092008-01-04 07:36:53 +0000707 MachineBasicBlock::iterator InsertPos = SuccToSinkTo->begin();
Evan Chengb339f3d2010-09-18 06:42:17 +0000708 while (InsertPos != SuccToSinkTo->end() && InsertPos->isPHI())
Chris Lattnerf3edc092008-01-04 07:36:53 +0000709 ++InsertPos;
Jim Grosbach01edd682010-06-03 23:49:57 +0000710
Devang Patel9de7a7d2011-09-07 00:07:58 +0000711 // collect matching debug values.
712 SmallVector<MachineInstr *, 2> DbgValuesToSink;
713 collectDebugValues(MI, DbgValuesToSink);
714
Chris Lattnerf3edc092008-01-04 07:36:53 +0000715 // Move the instruction.
716 SuccToSinkTo->splice(InsertPos, ParentBlock, MI,
717 ++MachineBasicBlock::iterator(MI));
Dan Gohmanc90f51c2010-05-13 20:34:42 +0000718
Devang Patel9de7a7d2011-09-07 00:07:58 +0000719 // Move debug values.
Craig Toppere1c1d362013-07-03 05:11:49 +0000720 for (SmallVectorImpl<MachineInstr *>::iterator DBI = DbgValuesToSink.begin(),
Devang Patel9de7a7d2011-09-07 00:07:58 +0000721 DBE = DbgValuesToSink.end(); DBI != DBE; ++DBI) {
722 MachineInstr *DbgMI = *DBI;
723 SuccToSinkTo->splice(InsertPos, ParentBlock, DbgMI,
724 ++MachineBasicBlock::iterator(DbgMI));
725 }
726
Juergen Ributzka4bea4942014-09-04 02:07:36 +0000727 // Conservatively, clear any kill flags, since it's possible that they are no
728 // longer correct.
729 MI->clearKillInfo();
Dan Gohmanc90f51c2010-05-13 20:34:42 +0000730
Chris Lattnerf3edc092008-01-04 07:36:53 +0000731 return true;
732}