MachineSink.cpp 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  1. //===- 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. //
  10. // This pass moves instructions into successor blocks when possible, so that
  11. // 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.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #include "llvm/ADT/SetVector.h"
  19. #include "llvm/ADT/SmallSet.h"
  20. #include "llvm/ADT/SmallVector.h"
  21. #include "llvm/ADT/SparseBitVector.h"
  22. #include "llvm/ADT/Statistic.h"
  23. #include "llvm/Analysis/AliasAnalysis.h"
  24. #include "llvm/CodeGen/MachineBasicBlock.h"
  25. #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
  26. #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
  27. #include "llvm/CodeGen/MachineDominators.h"
  28. #include "llvm/CodeGen/MachineFunction.h"
  29. #include "llvm/CodeGen/MachineFunctionPass.h"
  30. #include "llvm/CodeGen/MachineInstr.h"
  31. #include "llvm/CodeGen/MachineLoopInfo.h"
  32. #include "llvm/CodeGen/MachineOperand.h"
  33. #include "llvm/CodeGen/MachinePostDominators.h"
  34. #include "llvm/CodeGen/MachineRegisterInfo.h"
  35. #include "llvm/CodeGen/TargetInstrInfo.h"
  36. #include "llvm/CodeGen/TargetRegisterInfo.h"
  37. #include "llvm/CodeGen/TargetSubtargetInfo.h"
  38. #include "llvm/IR/BasicBlock.h"
  39. #include "llvm/IR/LLVMContext.h"
  40. #include "llvm/IR/DebugInfoMetadata.h"
  41. #include "llvm/Pass.h"
  42. #include "llvm/Support/BranchProbability.h"
  43. #include "llvm/Support/CommandLine.h"
  44. #include "llvm/Support/Debug.h"
  45. #include "llvm/Support/raw_ostream.h"
  46. #include <algorithm>
  47. #include <cassert>
  48. #include <cstdint>
  49. #include <map>
  50. #include <utility>
  51. #include <vector>
  52. using namespace llvm;
  53. #define DEBUG_TYPE "machine-sink"
  54. static cl::opt<bool>
  55. SplitEdges("machine-sink-split",
  56. cl::desc("Split critical edges during machine sinking"),
  57. cl::init(true), cl::Hidden);
  58. static cl::opt<bool>
  59. UseBlockFreqInfo("machine-sink-bfi",
  60. cl::desc("Use block frequency info to find successors to sink"),
  61. cl::init(true), cl::Hidden);
  62. static cl::opt<unsigned> SplitEdgeProbabilityThreshold(
  63. "machine-sink-split-probability-threshold",
  64. cl::desc(
  65. "Percentage threshold for splitting single-instruction critical edge. "
  66. "If the branch threshold is higher than this threshold, we allow "
  67. "speculative execution of up to 1 instruction to avoid branching to "
  68. "splitted critical edge"),
  69. cl::init(40), cl::Hidden);
  70. STATISTIC(NumSunk, "Number of machine instructions sunk");
  71. STATISTIC(NumSplit, "Number of critical edges split");
  72. STATISTIC(NumCoalesces, "Number of copies coalesced");
  73. STATISTIC(NumPostRACopySink, "Number of copies sunk after RA");
  74. namespace {
  75. class MachineSinking : public MachineFunctionPass {
  76. const TargetInstrInfo *TII;
  77. const TargetRegisterInfo *TRI;
  78. MachineRegisterInfo *MRI; // Machine register information
  79. MachineDominatorTree *DT; // Machine dominator tree
  80. MachinePostDominatorTree *PDT; // Machine post dominator tree
  81. MachineLoopInfo *LI;
  82. const MachineBlockFrequencyInfo *MBFI;
  83. const MachineBranchProbabilityInfo *MBPI;
  84. AliasAnalysis *AA;
  85. // Remember which edges have been considered for breaking.
  86. SmallSet<std::pair<MachineBasicBlock*, MachineBasicBlock*>, 8>
  87. CEBCandidates;
  88. // Remember which edges we are about to split.
  89. // This is different from CEBCandidates since those edges
  90. // will be split.
  91. SetVector<std::pair<MachineBasicBlock *, MachineBasicBlock *>> ToSplit;
  92. SparseBitVector<> RegsToClearKillFlags;
  93. using AllSuccsCache =
  94. std::map<MachineBasicBlock *, SmallVector<MachineBasicBlock *, 4>>;
  95. public:
  96. static char ID; // Pass identification
  97. MachineSinking() : MachineFunctionPass(ID) {
  98. initializeMachineSinkingPass(*PassRegistry::getPassRegistry());
  99. }
  100. bool runOnMachineFunction(MachineFunction &MF) override;
  101. void getAnalysisUsage(AnalysisUsage &AU) const override {
  102. AU.setPreservesCFG();
  103. MachineFunctionPass::getAnalysisUsage(AU);
  104. AU.addRequired<AAResultsWrapperPass>();
  105. AU.addRequired<MachineDominatorTree>();
  106. AU.addRequired<MachinePostDominatorTree>();
  107. AU.addRequired<MachineLoopInfo>();
  108. AU.addRequired<MachineBranchProbabilityInfo>();
  109. AU.addPreserved<MachineDominatorTree>();
  110. AU.addPreserved<MachinePostDominatorTree>();
  111. AU.addPreserved<MachineLoopInfo>();
  112. if (UseBlockFreqInfo)
  113. AU.addRequired<MachineBlockFrequencyInfo>();
  114. }
  115. void releaseMemory() override {
  116. CEBCandidates.clear();
  117. }
  118. private:
  119. bool ProcessBlock(MachineBasicBlock &MBB);
  120. bool isWorthBreakingCriticalEdge(MachineInstr &MI,
  121. MachineBasicBlock *From,
  122. MachineBasicBlock *To);
  123. /// \brief Postpone the splitting of the given critical
  124. /// edge (\p From, \p To).
  125. ///
  126. /// We do not split the edges on the fly. Indeed, this invalidates
  127. /// the dominance information and thus triggers a lot of updates
  128. /// of that information underneath.
  129. /// Instead, we postpone all the splits after each iteration of
  130. /// the main loop. That way, the information is at least valid
  131. /// for the lifetime of an iteration.
  132. ///
  133. /// \return True if the edge is marked as toSplit, false otherwise.
  134. /// False can be returned if, for instance, this is not profitable.
  135. bool PostponeSplitCriticalEdge(MachineInstr &MI,
  136. MachineBasicBlock *From,
  137. MachineBasicBlock *To,
  138. bool BreakPHIEdge);
  139. bool SinkInstruction(MachineInstr &MI, bool &SawStore,
  140. AllSuccsCache &AllSuccessors);
  141. bool AllUsesDominatedByBlock(unsigned Reg, MachineBasicBlock *MBB,
  142. MachineBasicBlock *DefMBB,
  143. bool &BreakPHIEdge, bool &LocalUse) const;
  144. MachineBasicBlock *FindSuccToSinkTo(MachineInstr &MI, MachineBasicBlock *MBB,
  145. bool &BreakPHIEdge, AllSuccsCache &AllSuccessors);
  146. bool isProfitableToSinkTo(unsigned Reg, MachineInstr &MI,
  147. MachineBasicBlock *MBB,
  148. MachineBasicBlock *SuccToSinkTo,
  149. AllSuccsCache &AllSuccessors);
  150. bool PerformTrivialForwardCoalescing(MachineInstr &MI,
  151. MachineBasicBlock *MBB);
  152. SmallVector<MachineBasicBlock *, 4> &
  153. GetAllSortedSuccessors(MachineInstr &MI, MachineBasicBlock *MBB,
  154. AllSuccsCache &AllSuccessors) const;
  155. };
  156. } // end anonymous namespace
  157. char MachineSinking::ID = 0;
  158. char &llvm::MachineSinkingID = MachineSinking::ID;
  159. INITIALIZE_PASS_BEGIN(MachineSinking, DEBUG_TYPE,
  160. "Machine code sinking", false, false)
  161. INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo)
  162. INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
  163. INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
  164. INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
  165. INITIALIZE_PASS_END(MachineSinking, DEBUG_TYPE,
  166. "Machine code sinking", false, false)
  167. bool MachineSinking::PerformTrivialForwardCoalescing(MachineInstr &MI,
  168. MachineBasicBlock *MBB) {
  169. if (!MI.isCopy())
  170. return false;
  171. unsigned SrcReg = MI.getOperand(1).getReg();
  172. unsigned DstReg = MI.getOperand(0).getReg();
  173. if (!TargetRegisterInfo::isVirtualRegister(SrcReg) ||
  174. !TargetRegisterInfo::isVirtualRegister(DstReg) ||
  175. !MRI->hasOneNonDBGUse(SrcReg))
  176. return false;
  177. const TargetRegisterClass *SRC = MRI->getRegClass(SrcReg);
  178. const TargetRegisterClass *DRC = MRI->getRegClass(DstReg);
  179. if (SRC != DRC)
  180. return false;
  181. MachineInstr *DefMI = MRI->getVRegDef(SrcReg);
  182. if (DefMI->isCopyLike())
  183. return false;
  184. DEBUG(dbgs() << "Coalescing: " << *DefMI);
  185. DEBUG(dbgs() << "*** to: " << MI);
  186. MRI->replaceRegWith(DstReg, SrcReg);
  187. MI.eraseFromParent();
  188. // Conservatively, clear any kill flags, since it's possible that they are no
  189. // longer correct.
  190. MRI->clearKillFlags(SrcReg);
  191. ++NumCoalesces;
  192. return true;
  193. }
  194. /// AllUsesDominatedByBlock - Return true if all uses of the specified register
  195. /// occur in blocks dominated by the specified block. If any use is in the
  196. /// definition block, then return false since it is never legal to move def
  197. /// after uses.
  198. bool
  199. MachineSinking::AllUsesDominatedByBlock(unsigned Reg,
  200. MachineBasicBlock *MBB,
  201. MachineBasicBlock *DefMBB,
  202. bool &BreakPHIEdge,
  203. bool &LocalUse) const {
  204. assert(TargetRegisterInfo::isVirtualRegister(Reg) &&
  205. "Only makes sense for vregs");
  206. // Ignore debug uses because debug info doesn't affect the code.
  207. if (MRI->use_nodbg_empty(Reg))
  208. return true;
  209. // BreakPHIEdge is true if all the uses are in the successor MBB being sunken
  210. // into and they are all PHI nodes. In this case, machine-sink must break
  211. // the critical edge first. e.g.
  212. //
  213. // %bb.1: derived from LLVM BB %bb4.preheader
  214. // Predecessors according to CFG: %bb.0
  215. // ...
  216. // %reg16385 = DEC64_32r %reg16437, implicit-def dead %eflags
  217. // ...
  218. // JE_4 <%bb.37>, implicit %eflags
  219. // Successors according to CFG: %bb.37 %bb.2
  220. //
  221. // %bb.2: derived from LLVM BB %bb.nph
  222. // Predecessors according to CFG: %bb.0 %bb.1
  223. // %reg16386 = PHI %reg16434, %bb.0, %reg16385, %bb.1
  224. BreakPHIEdge = true;
  225. for (MachineOperand &MO : MRI->use_nodbg_operands(Reg)) {
  226. MachineInstr *UseInst = MO.getParent();
  227. unsigned OpNo = &MO - &UseInst->getOperand(0);
  228. MachineBasicBlock *UseBlock = UseInst->getParent();
  229. if (!(UseBlock == MBB && UseInst->isPHI() &&
  230. UseInst->getOperand(OpNo+1).getMBB() == DefMBB)) {
  231. BreakPHIEdge = false;
  232. break;
  233. }
  234. }
  235. if (BreakPHIEdge)
  236. return true;
  237. for (MachineOperand &MO : MRI->use_nodbg_operands(Reg)) {
  238. // Determine the block of the use.
  239. MachineInstr *UseInst = MO.getParent();
  240. unsigned OpNo = &MO - &UseInst->getOperand(0);
  241. MachineBasicBlock *UseBlock = UseInst->getParent();
  242. if (UseInst->isPHI()) {
  243. // PHI nodes use the operand in the predecessor block, not the block with
  244. // the PHI.
  245. UseBlock = UseInst->getOperand(OpNo+1).getMBB();
  246. } else if (UseBlock == DefMBB) {
  247. LocalUse = true;
  248. return false;
  249. }
  250. // Check that it dominates.
  251. if (!DT->dominates(MBB, UseBlock))
  252. return false;
  253. }
  254. return true;
  255. }
  256. bool MachineSinking::runOnMachineFunction(MachineFunction &MF) {
  257. if (skipFunction(MF.getFunction()))
  258. return false;
  259. DEBUG(dbgs() << "******** Machine Sinking ********\n");
  260. TII = MF.getSubtarget().getInstrInfo();
  261. TRI = MF.getSubtarget().getRegisterInfo();
  262. MRI = &MF.getRegInfo();
  263. DT = &getAnalysis<MachineDominatorTree>();
  264. PDT = &getAnalysis<MachinePostDominatorTree>();
  265. LI = &getAnalysis<MachineLoopInfo>();
  266. MBFI = UseBlockFreqInfo ? &getAnalysis<MachineBlockFrequencyInfo>() : nullptr;
  267. MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
  268. AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
  269. bool EverMadeChange = false;
  270. while (true) {
  271. bool MadeChange = false;
  272. // Process all basic blocks.
  273. CEBCandidates.clear();
  274. ToSplit.clear();
  275. for (auto &MBB: MF)
  276. MadeChange |= ProcessBlock(MBB);
  277. // If we have anything we marked as toSplit, split it now.
  278. for (auto &Pair : ToSplit) {
  279. auto NewSucc = Pair.first->SplitCriticalEdge(Pair.second, *this);
  280. if (NewSucc != nullptr) {
  281. DEBUG(dbgs() << " *** Splitting critical edge: "
  282. << printMBBReference(*Pair.first) << " -- "
  283. << printMBBReference(*NewSucc) << " -- "
  284. << printMBBReference(*Pair.second) << '\n');
  285. MadeChange = true;
  286. ++NumSplit;
  287. } else
  288. DEBUG(dbgs() << " *** Not legal to break critical edge\n");
  289. }
  290. // If this iteration over the code changed anything, keep iterating.
  291. if (!MadeChange) break;
  292. EverMadeChange = true;
  293. }
  294. // Now clear any kill flags for recorded registers.
  295. for (auto I : RegsToClearKillFlags)
  296. MRI->clearKillFlags(I);
  297. RegsToClearKillFlags.clear();
  298. return EverMadeChange;
  299. }
  300. bool MachineSinking::ProcessBlock(MachineBasicBlock &MBB) {
  301. // Can't sink anything out of a block that has less than two successors.
  302. if (MBB.succ_size() <= 1 || MBB.empty()) return false;
  303. // Don't bother sinking code out of unreachable blocks. In addition to being
  304. // unprofitable, it can also lead to infinite looping, because in an
  305. // unreachable loop there may be nowhere to stop.
  306. if (!DT->isReachableFromEntry(&MBB)) return false;
  307. bool MadeChange = false;
  308. // Cache all successors, sorted by frequency info and loop depth.
  309. AllSuccsCache AllSuccessors;
  310. // Walk the basic block bottom-up. Remember if we saw a store.
  311. MachineBasicBlock::iterator I = MBB.end();
  312. --I;
  313. bool ProcessedBegin, SawStore = false;
  314. do {
  315. MachineInstr &MI = *I; // The instruction to sink.
  316. // Predecrement I (if it's not begin) so that it isn't invalidated by
  317. // sinking.
  318. ProcessedBegin = I == MBB.begin();
  319. if (!ProcessedBegin)
  320. --I;
  321. if (MI.isDebugValue())
  322. continue;
  323. bool Joined = PerformTrivialForwardCoalescing(MI, &MBB);
  324. if (Joined) {
  325. MadeChange = true;
  326. continue;
  327. }
  328. if (SinkInstruction(MI, SawStore, AllSuccessors)) {
  329. ++NumSunk;
  330. MadeChange = true;
  331. }
  332. // If we just processed the first instruction in the block, we're done.
  333. } while (!ProcessedBegin);
  334. return MadeChange;
  335. }
  336. bool MachineSinking::isWorthBreakingCriticalEdge(MachineInstr &MI,
  337. MachineBasicBlock *From,
  338. MachineBasicBlock *To) {
  339. // FIXME: Need much better heuristics.
  340. // If the pass has already considered breaking this edge (during this pass
  341. // through the function), then let's go ahead and break it. This means
  342. // sinking multiple "cheap" instructions into the same block.
  343. if (!CEBCandidates.insert(std::make_pair(From, To)).second)
  344. return true;
  345. if (!MI.isCopy() && !TII->isAsCheapAsAMove(MI))
  346. return true;
  347. if (From->isSuccessor(To) && MBPI->getEdgeProbability(From, To) <=
  348. BranchProbability(SplitEdgeProbabilityThreshold, 100))
  349. return true;
  350. // MI is cheap, we probably don't want to break the critical edge for it.
  351. // However, if this would allow some definitions of its source operands
  352. // to be sunk then it's probably worth it.
  353. for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
  354. const MachineOperand &MO = MI.getOperand(i);
  355. if (!MO.isReg() || !MO.isUse())
  356. continue;
  357. unsigned Reg = MO.getReg();
  358. if (Reg == 0)
  359. continue;
  360. // We don't move live definitions of physical registers,
  361. // so sinking their uses won't enable any opportunities.
  362. if (TargetRegisterInfo::isPhysicalRegister(Reg))
  363. continue;
  364. // If this instruction is the only user of a virtual register,
  365. // check if breaking the edge will enable sinking
  366. // both this instruction and the defining instruction.
  367. if (MRI->hasOneNonDBGUse(Reg)) {
  368. // If the definition resides in same MBB,
  369. // claim it's likely we can sink these together.
  370. // If definition resides elsewhere, we aren't
  371. // blocking it from being sunk so don't break the edge.
  372. MachineInstr *DefMI = MRI->getVRegDef(Reg);
  373. if (DefMI->getParent() == MI.getParent())
  374. return true;
  375. }
  376. }
  377. return false;
  378. }
  379. bool MachineSinking::PostponeSplitCriticalEdge(MachineInstr &MI,
  380. MachineBasicBlock *FromBB,
  381. MachineBasicBlock *ToBB,
  382. bool BreakPHIEdge) {
  383. if (!isWorthBreakingCriticalEdge(MI, FromBB, ToBB))
  384. return false;
  385. // Avoid breaking back edge. From == To means backedge for single BB loop.
  386. if (!SplitEdges || FromBB == ToBB)
  387. return false;
  388. // Check for backedges of more "complex" loops.
  389. if (LI->getLoopFor(FromBB) == LI->getLoopFor(ToBB) &&
  390. LI->isLoopHeader(ToBB))
  391. return false;
  392. // It's not always legal to break critical edges and sink the computation
  393. // to the edge.
  394. //
  395. // %bb.1:
  396. // v1024
  397. // Beq %bb.3
  398. // <fallthrough>
  399. // %bb.2:
  400. // ... no uses of v1024
  401. // <fallthrough>
  402. // %bb.3:
  403. // ...
  404. // = v1024
  405. //
  406. // If %bb.1 -> %bb.3 edge is broken and computation of v1024 is inserted:
  407. //
  408. // %bb.1:
  409. // ...
  410. // Bne %bb.2
  411. // %bb.4:
  412. // v1024 =
  413. // B %bb.3
  414. // %bb.2:
  415. // ... no uses of v1024
  416. // <fallthrough>
  417. // %bb.3:
  418. // ...
  419. // = v1024
  420. //
  421. // This is incorrect since v1024 is not computed along the %bb.1->%bb.2->%bb.3
  422. // flow. We need to ensure the new basic block where the computation is
  423. // sunk to dominates all the uses.
  424. // It's only legal to break critical edge and sink the computation to the
  425. // new block if all the predecessors of "To", except for "From", are
  426. // not dominated by "From". Given SSA property, this means these
  427. // predecessors are dominated by "To".
  428. //
  429. // There is no need to do this check if all the uses are PHI nodes. PHI
  430. // sources are only defined on the specific predecessor edges.
  431. if (!BreakPHIEdge) {
  432. for (MachineBasicBlock::pred_iterator PI = ToBB->pred_begin(),
  433. E = ToBB->pred_end(); PI != E; ++PI) {
  434. if (*PI == FromBB)
  435. continue;
  436. if (!DT->dominates(ToBB, *PI))
  437. return false;
  438. }
  439. }
  440. ToSplit.insert(std::make_pair(FromBB, ToBB));
  441. return true;
  442. }
  443. /// collectDebgValues - Scan instructions following MI and collect any
  444. /// matching DBG_VALUEs.
  445. static void collectDebugValues(MachineInstr &MI,
  446. SmallVectorImpl<MachineInstr *> &DbgValues) {
  447. DbgValues.clear();
  448. if (!MI.getOperand(0).isReg())
  449. return;
  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. /// isProfitableToSinkTo - Return true if it is profitable to sink MI.
  461. bool MachineSinking::isProfitableToSinkTo(unsigned Reg, MachineInstr &MI,
  462. MachineBasicBlock *MBB,
  463. MachineBasicBlock *SuccToSinkTo,
  464. AllSuccsCache &AllSuccessors) {
  465. assert (SuccToSinkTo && "Invalid SinkTo Candidate BB");
  466. if (MBB == SuccToSinkTo)
  467. return false;
  468. // It is profitable if SuccToSinkTo does not post dominate current block.
  469. if (!PDT->dominates(SuccToSinkTo, MBB))
  470. return true;
  471. // It is profitable to sink an instruction from a deeper loop to a shallower
  472. // loop, even if the latter post-dominates the former (PR21115).
  473. if (LI->getLoopDepth(MBB) > LI->getLoopDepth(SuccToSinkTo))
  474. return true;
  475. // Check if only use in post dominated block is PHI instruction.
  476. bool NonPHIUse = false;
  477. for (MachineInstr &UseInst : MRI->use_nodbg_instructions(Reg)) {
  478. MachineBasicBlock *UseBlock = UseInst.getParent();
  479. if (UseBlock == SuccToSinkTo && !UseInst.isPHI())
  480. NonPHIUse = true;
  481. }
  482. if (!NonPHIUse)
  483. return true;
  484. // If SuccToSinkTo post dominates then also it may be profitable if MI
  485. // can further profitably sinked into another block in next round.
  486. bool BreakPHIEdge = false;
  487. // FIXME - If finding successor is compile time expensive then cache results.
  488. if (MachineBasicBlock *MBB2 =
  489. FindSuccToSinkTo(MI, SuccToSinkTo, BreakPHIEdge, AllSuccessors))
  490. return isProfitableToSinkTo(Reg, MI, SuccToSinkTo, MBB2, AllSuccessors);
  491. // If SuccToSinkTo is final destination and it is a post dominator of current
  492. // block then it is not profitable to sink MI into SuccToSinkTo block.
  493. return false;
  494. }
  495. /// Get the sorted sequence of successors for this MachineBasicBlock, possibly
  496. /// computing it if it was not already cached.
  497. SmallVector<MachineBasicBlock *, 4> &
  498. MachineSinking::GetAllSortedSuccessors(MachineInstr &MI, MachineBasicBlock *MBB,
  499. AllSuccsCache &AllSuccessors) const {
  500. // Do we have the sorted successors in cache ?
  501. auto Succs = AllSuccessors.find(MBB);
  502. if (Succs != AllSuccessors.end())
  503. return Succs->second;
  504. SmallVector<MachineBasicBlock *, 4> AllSuccs(MBB->succ_begin(),
  505. MBB->succ_end());
  506. // Handle cases where sinking can happen but where the sink point isn't a
  507. // successor. For example:
  508. //
  509. // x = computation
  510. // if () {} else {}
  511. // use x
  512. //
  513. const std::vector<MachineDomTreeNode *> &Children =
  514. DT->getNode(MBB)->getChildren();
  515. for (const auto &DTChild : Children)
  516. // DomTree children of MBB that have MBB as immediate dominator are added.
  517. if (DTChild->getIDom()->getBlock() == MI.getParent() &&
  518. // Skip MBBs already added to the AllSuccs vector above.
  519. !MBB->isSuccessor(DTChild->getBlock()))
  520. AllSuccs.push_back(DTChild->getBlock());
  521. // Sort Successors according to their loop depth or block frequency info.
  522. std::stable_sort(
  523. AllSuccs.begin(), AllSuccs.end(),
  524. [this](const MachineBasicBlock *L, const MachineBasicBlock *R) {
  525. uint64_t LHSFreq = MBFI ? MBFI->getBlockFreq(L).getFrequency() : 0;
  526. uint64_t RHSFreq = MBFI ? MBFI->getBlockFreq(R).getFrequency() : 0;
  527. bool HasBlockFreq = LHSFreq != 0 && RHSFreq != 0;
  528. return HasBlockFreq ? LHSFreq < RHSFreq
  529. : LI->getLoopDepth(L) < LI->getLoopDepth(R);
  530. });
  531. auto it = AllSuccessors.insert(std::make_pair(MBB, AllSuccs));
  532. return it.first->second;
  533. }
  534. /// FindSuccToSinkTo - Find a successor to sink this instruction to.
  535. MachineBasicBlock *
  536. MachineSinking::FindSuccToSinkTo(MachineInstr &MI, MachineBasicBlock *MBB,
  537. bool &BreakPHIEdge,
  538. AllSuccsCache &AllSuccessors) {
  539. assert (MBB && "Invalid MachineBasicBlock!");
  540. // Loop over all the operands of the specified instruction. If there is
  541. // anything we can't handle, bail out.
  542. // SuccToSinkTo - This is the successor to sink this instruction to, once we
  543. // decide.
  544. MachineBasicBlock *SuccToSinkTo = nullptr;
  545. for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
  546. const MachineOperand &MO = MI.getOperand(i);
  547. if (!MO.isReg()) continue; // Ignore non-register operands.
  548. unsigned Reg = MO.getReg();
  549. if (Reg == 0) continue;
  550. if (TargetRegisterInfo::isPhysicalRegister(Reg)) {
  551. if (MO.isUse()) {
  552. // If the physreg has no defs anywhere, it's just an ambient register
  553. // and we can freely move its uses. Alternatively, if it's allocatable,
  554. // it could get allocated to something with a def during allocation.
  555. if (!MRI->isConstantPhysReg(Reg))
  556. return nullptr;
  557. } else if (!MO.isDead()) {
  558. // A def that isn't dead. We can't move it.
  559. return nullptr;
  560. }
  561. } else {
  562. // Virtual register uses are always safe to sink.
  563. if (MO.isUse()) continue;
  564. // If it's not safe to move defs of the register class, then abort.
  565. if (!TII->isSafeToMoveRegClassDefs(MRI->getRegClass(Reg)))
  566. return nullptr;
  567. // Virtual register defs can only be sunk if all their uses are in blocks
  568. // dominated by one of the successors.
  569. if (SuccToSinkTo) {
  570. // If a previous operand picked a block to sink to, then this operand
  571. // must be sinkable to the same block.
  572. bool LocalUse = false;
  573. if (!AllUsesDominatedByBlock(Reg, SuccToSinkTo, MBB,
  574. BreakPHIEdge, LocalUse))
  575. return nullptr;
  576. continue;
  577. }
  578. // Otherwise, we should look at all the successors and decide which one
  579. // we should sink to. If we have reliable block frequency information
  580. // (frequency != 0) available, give successors with smaller frequencies
  581. // higher priority, otherwise prioritize smaller loop depths.
  582. for (MachineBasicBlock *SuccBlock :
  583. GetAllSortedSuccessors(MI, MBB, AllSuccessors)) {
  584. bool LocalUse = false;
  585. if (AllUsesDominatedByBlock(Reg, SuccBlock, MBB,
  586. BreakPHIEdge, LocalUse)) {
  587. SuccToSinkTo = SuccBlock;
  588. break;
  589. }
  590. if (LocalUse)
  591. // Def is used locally, it's never safe to move this def.
  592. return nullptr;
  593. }
  594. // If we couldn't find a block to sink to, ignore this instruction.
  595. if (!SuccToSinkTo)
  596. return nullptr;
  597. if (!isProfitableToSinkTo(Reg, MI, MBB, SuccToSinkTo, AllSuccessors))
  598. return nullptr;
  599. }
  600. }
  601. // It is not possible to sink an instruction into its own block. This can
  602. // happen with loops.
  603. if (MBB == SuccToSinkTo)
  604. return nullptr;
  605. // It's not safe to sink instructions to EH landing pad. Control flow into
  606. // landing pad is implicitly defined.
  607. if (SuccToSinkTo && SuccToSinkTo->isEHPad())
  608. return nullptr;
  609. return SuccToSinkTo;
  610. }
  611. /// \brief Return true if MI is likely to be usable as a memory operation by the
  612. /// implicit null check optimization.
  613. ///
  614. /// This is a "best effort" heuristic, and should not be relied upon for
  615. /// correctness. This returning true does not guarantee that the implicit null
  616. /// check optimization is legal over MI, and this returning false does not
  617. /// guarantee MI cannot possibly be used to do a null check.
  618. static bool SinkingPreventsImplicitNullCheck(MachineInstr &MI,
  619. const TargetInstrInfo *TII,
  620. const TargetRegisterInfo *TRI) {
  621. using MachineBranchPredicate = TargetInstrInfo::MachineBranchPredicate;
  622. auto *MBB = MI.getParent();
  623. if (MBB->pred_size() != 1)
  624. return false;
  625. auto *PredMBB = *MBB->pred_begin();
  626. auto *PredBB = PredMBB->getBasicBlock();
  627. // Frontends that don't use implicit null checks have no reason to emit
  628. // branches with make.implicit metadata, and this function should always
  629. // return false for them.
  630. if (!PredBB ||
  631. !PredBB->getTerminator()->getMetadata(LLVMContext::MD_make_implicit))
  632. return false;
  633. unsigned BaseReg;
  634. int64_t Offset;
  635. if (!TII->getMemOpBaseRegImmOfs(MI, BaseReg, Offset, TRI))
  636. return false;
  637. if (!(MI.mayLoad() && !MI.isPredicable()))
  638. return false;
  639. MachineBranchPredicate MBP;
  640. if (TII->analyzeBranchPredicate(*PredMBB, MBP, false))
  641. return false;
  642. return MBP.LHS.isReg() && MBP.RHS.isImm() && MBP.RHS.getImm() == 0 &&
  643. (MBP.Predicate == MachineBranchPredicate::PRED_NE ||
  644. MBP.Predicate == MachineBranchPredicate::PRED_EQ) &&
  645. MBP.LHS.getReg() == BaseReg;
  646. }
  647. /// SinkInstruction - Determine whether it is safe to sink the specified machine
  648. /// instruction out of its current block into a successor.
  649. bool MachineSinking::SinkInstruction(MachineInstr &MI, bool &SawStore,
  650. AllSuccsCache &AllSuccessors) {
  651. // Don't sink instructions that the target prefers not to sink.
  652. if (!TII->shouldSink(MI))
  653. return false;
  654. // Check if it's safe to move the instruction.
  655. if (!MI.isSafeToMove(AA, SawStore))
  656. return false;
  657. // Convergent operations may not be made control-dependent on additional
  658. // values.
  659. if (MI.isConvergent())
  660. return false;
  661. // Don't break implicit null checks. This is a performance heuristic, and not
  662. // required for correctness.
  663. if (SinkingPreventsImplicitNullCheck(MI, TII, TRI))
  664. return false;
  665. // FIXME: This should include support for sinking instructions within the
  666. // block they are currently in to shorten the live ranges. We often get
  667. // instructions sunk into the top of a large block, but it would be better to
  668. // also sink them down before their first use in the block. This xform has to
  669. // be careful not to *increase* register pressure though, e.g. sinking
  670. // "x = y + z" down if it kills y and z would increase the live ranges of y
  671. // and z and only shrink the live range of x.
  672. bool BreakPHIEdge = false;
  673. MachineBasicBlock *ParentBlock = MI.getParent();
  674. MachineBasicBlock *SuccToSinkTo =
  675. FindSuccToSinkTo(MI, ParentBlock, BreakPHIEdge, AllSuccessors);
  676. // If there are no outputs, it must have side-effects.
  677. if (!SuccToSinkTo)
  678. return false;
  679. // If the instruction to move defines a dead physical register which is live
  680. // when leaving the basic block, don't move it because it could turn into a
  681. // "zombie" define of that preg. E.g., EFLAGS. (<rdar://problem/8030636>)
  682. for (unsigned I = 0, E = MI.getNumOperands(); I != E; ++I) {
  683. const MachineOperand &MO = MI.getOperand(I);
  684. if (!MO.isReg()) continue;
  685. unsigned Reg = MO.getReg();
  686. if (Reg == 0 || !TargetRegisterInfo::isPhysicalRegister(Reg)) continue;
  687. if (SuccToSinkTo->isLiveIn(Reg))
  688. return false;
  689. }
  690. DEBUG(dbgs() << "Sink instr " << MI << "\tinto block " << *SuccToSinkTo);
  691. // If the block has multiple predecessors, this is a critical edge.
  692. // Decide if we can sink along it or need to break the edge.
  693. if (SuccToSinkTo->pred_size() > 1) {
  694. // We cannot sink a load across a critical edge - there may be stores in
  695. // other code paths.
  696. bool TryBreak = false;
  697. bool store = true;
  698. if (!MI.isSafeToMove(AA, store)) {
  699. DEBUG(dbgs() << " *** NOTE: Won't sink load along critical edge.\n");
  700. TryBreak = true;
  701. }
  702. // We don't want to sink across a critical edge if we don't dominate the
  703. // successor. We could be introducing calculations to new code paths.
  704. if (!TryBreak && !DT->dominates(ParentBlock, SuccToSinkTo)) {
  705. DEBUG(dbgs() << " *** NOTE: Critical edge found\n");
  706. TryBreak = true;
  707. }
  708. // Don't sink instructions into a loop.
  709. if (!TryBreak && LI->isLoopHeader(SuccToSinkTo)) {
  710. DEBUG(dbgs() << " *** NOTE: Loop header found\n");
  711. TryBreak = true;
  712. }
  713. // Otherwise we are OK with sinking along a critical edge.
  714. if (!TryBreak)
  715. DEBUG(dbgs() << "Sinking along critical edge.\n");
  716. else {
  717. // Mark this edge as to be split.
  718. // If the edge can actually be split, the next iteration of the main loop
  719. // will sink MI in the newly created block.
  720. bool Status =
  721. PostponeSplitCriticalEdge(MI, ParentBlock, SuccToSinkTo, BreakPHIEdge);
  722. if (!Status)
  723. DEBUG(dbgs() << " *** PUNTING: Not legal or profitable to "
  724. "break critical edge\n");
  725. // The instruction will not be sunk this time.
  726. return false;
  727. }
  728. }
  729. if (BreakPHIEdge) {
  730. // BreakPHIEdge is true if all the uses are in the successor MBB being
  731. // sunken into and they are all PHI nodes. In this case, machine-sink must
  732. // break the critical edge first.
  733. bool Status = PostponeSplitCriticalEdge(MI, ParentBlock,
  734. SuccToSinkTo, BreakPHIEdge);
  735. if (!Status)
  736. DEBUG(dbgs() << " *** PUNTING: Not legal or profitable to "
  737. "break critical edge\n");
  738. // The instruction will not be sunk this time.
  739. return false;
  740. }
  741. // Determine where to insert into. Skip phi nodes.
  742. MachineBasicBlock::iterator InsertPos = SuccToSinkTo->begin();
  743. while (InsertPos != SuccToSinkTo->end() && InsertPos->isPHI())
  744. ++InsertPos;
  745. // collect matching debug values.
  746. SmallVector<MachineInstr *, 2> DbgValuesToSink;
  747. collectDebugValues(MI, DbgValuesToSink);
  748. // Merge or erase debug location to ensure consistent stepping in profilers
  749. // and debuggers.
  750. if (!SuccToSinkTo->empty() && InsertPos != SuccToSinkTo->end())
  751. MI.setDebugLoc(DILocation::getMergedLocation(MI.getDebugLoc(),
  752. InsertPos->getDebugLoc()));
  753. else
  754. MI.setDebugLoc(DebugLoc());
  755. // Move the instruction.
  756. SuccToSinkTo->splice(InsertPos, ParentBlock, MI,
  757. ++MachineBasicBlock::iterator(MI));
  758. // Move previously adjacent debug value instructions to the insert position.
  759. for (SmallVectorImpl<MachineInstr *>::iterator DBI = DbgValuesToSink.begin(),
  760. DBE = DbgValuesToSink.end(); DBI != DBE; ++DBI) {
  761. MachineInstr *DbgMI = *DBI;
  762. SuccToSinkTo->splice(InsertPos, ParentBlock, DbgMI,
  763. ++MachineBasicBlock::iterator(DbgMI));
  764. }
  765. // Conservatively, clear any kill flags, since it's possible that they are no
  766. // longer correct.
  767. // Note that we have to clear the kill flags for any register this instruction
  768. // uses as we may sink over another instruction which currently kills the
  769. // used registers.
  770. for (MachineOperand &MO : MI.operands()) {
  771. if (MO.isReg() && MO.isUse())
  772. RegsToClearKillFlags.set(MO.getReg()); // Remember to clear kill flags.
  773. }
  774. return true;
  775. }
  776. //===----------------------------------------------------------------------===//
  777. // This pass is not intended to be a replacement or a complete alternative
  778. // for the pre-ra machine sink pass. It is only designed to sink COPY
  779. // instructions which should be handled after RA.
  780. //
  781. // This pass sinks COPY instructions into a successor block, if the COPY is not
  782. // used in the current block and the COPY is live-in to a single successor
  783. // (i.e., doesn't require the COPY to be duplicated). This avoids executing the
  784. // copy on paths where their results aren't needed. This also exposes
  785. // additional opportunites for dead copy elimination and shrink wrapping.
  786. //
  787. // These copies were either not handled by or are inserted after the MachineSink
  788. // pass. As an example of the former case, the MachineSink pass cannot sink
  789. // COPY instructions with allocatable source registers; for AArch64 these type
  790. // of copy instructions are frequently used to move function parameters (PhyReg)
  791. // into virtual registers in the entry block.
  792. //
  793. // For the machine IR below, this pass will sink %w19 in the entry into its
  794. // successor (%bb.1) because %w19 is only live-in in %bb.1.
  795. // %bb.0:
  796. // %wzr = SUBSWri %w1, 1
  797. // %w19 = COPY %w0
  798. // Bcc 11, %bb.2
  799. // %bb.1:
  800. // Live Ins: %w19
  801. // BL @fun
  802. // %w0 = ADDWrr %w0, %w19
  803. // RET %w0
  804. // %bb.2:
  805. // %w0 = COPY %wzr
  806. // RET %w0
  807. // As we sink %w19 (CSR in AArch64) into %bb.1, the shrink-wrapping pass will be
  808. // able to see %bb.0 as a candidate.
  809. //===----------------------------------------------------------------------===//
  810. namespace {
  811. class PostRAMachineSinking : public MachineFunctionPass {
  812. public:
  813. bool runOnMachineFunction(MachineFunction &MF) override;
  814. static char ID;
  815. PostRAMachineSinking() : MachineFunctionPass(ID) {}
  816. StringRef getPassName() const override { return "PostRA Machine Sink"; }
  817. void getAnalysisUsage(AnalysisUsage &AU) const override {
  818. AU.setPreservesCFG();
  819. MachineFunctionPass::getAnalysisUsage(AU);
  820. }
  821. private:
  822. /// Track which registers have been modified and used.
  823. BitVector ModifiedRegs, UsedRegs;
  824. /// Sink Copy instructions unused in the same block close to their uses in
  825. /// successors.
  826. bool tryToSinkCopy(MachineBasicBlock &BB, MachineFunction &MF,
  827. const TargetRegisterInfo *TRI, const TargetInstrInfo *TII);
  828. };
  829. } // namespace
  830. char PostRAMachineSinking::ID = 0;
  831. char &llvm::PostRAMachineSinkingID = PostRAMachineSinking::ID;
  832. INITIALIZE_PASS(PostRAMachineSinking, "postra-machine-sink",
  833. "PostRA Machine Sink", false, false)
  834. static MachineBasicBlock *
  835. getSingleLiveInSuccBB(MachineBasicBlock &CurBB,
  836. ArrayRef<MachineBasicBlock *> SinkableBBs, unsigned Reg,
  837. const TargetRegisterInfo *TRI) {
  838. SmallSet<unsigned, 8> AliasedRegs;
  839. for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI)
  840. AliasedRegs.insert(*AI);
  841. // Try to find a single sinkable successor in which Reg is live-in.
  842. MachineBasicBlock *BB = nullptr;
  843. for (auto *SI : SinkableBBs) {
  844. if (SI->isLiveIn(Reg)) {
  845. // If BB is set here, Reg is live-in to at least two sinkable successors,
  846. // so quit.
  847. if (BB)
  848. return nullptr;
  849. BB = SI;
  850. }
  851. }
  852. // Reg is not live-in to any sinkable successors.
  853. if (!BB)
  854. return nullptr;
  855. // Check if any register aliased with Reg is live-in in other successors.
  856. for (auto *SI : CurBB.successors()) {
  857. if (SI == BB)
  858. continue;
  859. for (const auto LI : SI->liveins())
  860. if (AliasedRegs.count(LI.PhysReg))
  861. return nullptr;
  862. }
  863. return BB;
  864. }
  865. bool PostRAMachineSinking::tryToSinkCopy(MachineBasicBlock &CurBB,
  866. MachineFunction &MF,
  867. const TargetRegisterInfo *TRI,
  868. const TargetInstrInfo *TII) {
  869. SmallVector<MachineBasicBlock *, 2> SinkableBBs;
  870. // FIXME: For now, we sink only to a successor which has a single predecessor
  871. // so that we can directly sink COPY instructions to the successor without
  872. // adding any new block or branch instruction.
  873. for (MachineBasicBlock *SI : CurBB.successors())
  874. if (!SI->livein_empty() && SI->pred_size() == 1)
  875. SinkableBBs.push_back(SI);
  876. if (SinkableBBs.empty())
  877. return false;
  878. bool Changed = false;
  879. // Track which registers have been modified and used between the end of the
  880. // block and the current instruction.
  881. ModifiedRegs.reset();
  882. UsedRegs.reset();
  883. for (auto I = CurBB.rbegin(), E = CurBB.rend(); I != E;) {
  884. MachineInstr *MI = &*I;
  885. ++I;
  886. // Do not move any instruction across function call.
  887. if (MI->isCall())
  888. return false;
  889. if (!MI->isCopy() || !MI->getOperand(0).isRenamable()) {
  890. TII->trackRegDefsUses(*MI, ModifiedRegs, UsedRegs, TRI);
  891. continue;
  892. }
  893. unsigned DefReg = MI->getOperand(0).getReg();
  894. unsigned SrcReg = MI->getOperand(1).getReg();
  895. // Don't sink the COPY if it would violate a register dependency.
  896. if (ModifiedRegs[DefReg] || ModifiedRegs[SrcReg] || UsedRegs[DefReg]) {
  897. TII->trackRegDefsUses(*MI, ModifiedRegs, UsedRegs, TRI);
  898. continue;
  899. }
  900. MachineBasicBlock *SuccBB =
  901. getSingleLiveInSuccBB(CurBB, SinkableBBs, DefReg, TRI);
  902. // Don't sink if we cannot find a single sinkable successor in which Reg
  903. // is live-in.
  904. if (!SuccBB) {
  905. TII->trackRegDefsUses(*MI, ModifiedRegs, UsedRegs, TRI);
  906. continue;
  907. }
  908. assert((SuccBB->pred_size() == 1 && *SuccBB->pred_begin() == &CurBB) &&
  909. "Unexpected predecessor");
  910. // Clear the kill flag if SrcReg is killed between MI and the end of the
  911. // block.
  912. if (UsedRegs[SrcReg]) {
  913. MachineBasicBlock::iterator NI = std::next(MI->getIterator());
  914. for (MachineInstr &UI : make_range(NI, CurBB.end())) {
  915. if (UI.killsRegister(SrcReg, TRI)) {
  916. UI.clearRegisterKills(SrcReg, TRI);
  917. MI->getOperand(1).setIsKill(true);
  918. break;
  919. }
  920. }
  921. }
  922. MachineBasicBlock::iterator InsertPos = SuccBB->getFirstNonPHI();
  923. SuccBB->splice(InsertPos, &CurBB, MI);
  924. SuccBB->removeLiveIn(DefReg);
  925. if (!SuccBB->isLiveIn(SrcReg))
  926. SuccBB->addLiveIn(SrcReg);
  927. Changed = true;
  928. ++NumPostRACopySink;
  929. }
  930. return Changed;
  931. }
  932. bool PostRAMachineSinking::runOnMachineFunction(MachineFunction &MF) {
  933. bool Changed = false;
  934. const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
  935. const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
  936. ModifiedRegs.resize(TRI->getNumRegs());
  937. UsedRegs.resize(TRI->getNumRegs());
  938. for (auto &BB : MF)
  939. Changed |= tryToSinkCopy(BB, MF, TRI, TII);
  940. return Changed;
  941. }