Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 1 | //===- MergedLoadStoreMotion.cpp - merge and hoist/sink load/stores -------===// |
| 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 | //! \file |
| 11 | //! \brief This pass performs merges of loads and stores on both sides of a |
| 12 | // diamond (hammock). It hoists the loads and sinks the stores. |
| 13 | // |
| 14 | // The algorithm iteratively hoists two loads to the same address out of a |
| 15 | // diamond (hammock) and merges them into a single load in the header. Similar |
| 16 | // it sinks and merges two stores to the tail block (footer). The algorithm |
| 17 | // iterates over the instructions of one side of the diamond and attempts to |
| 18 | // find a matching load/store on the other side. It hoists / sinks when it |
| 19 | // thinks it safe to do so. This optimization helps with eg. hiding load |
| 20 | // latencies, triggering if-conversion, and reducing static code size. |
| 21 | // |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | // |
| 24 | // |
| 25 | // Example: |
| 26 | // Diamond shaped code before merge: |
| 27 | // |
| 28 | // header: |
| 29 | // br %cond, label %if.then, label %if.else |
Gerolf Hoflehner | ea96a3d | 2014-08-07 23:19:55 +0000 | [diff] [blame] | 30 | // + + |
| 31 | // + + |
| 32 | // + + |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 33 | // if.then: if.else: |
| 34 | // %lt = load %addr_l %le = load %addr_l |
| 35 | // <use %lt> <use %le> |
| 36 | // <...> <...> |
| 37 | // store %st, %addr_s store %se, %addr_s |
| 38 | // br label %if.end br label %if.end |
Gerolf Hoflehner | ea96a3d | 2014-08-07 23:19:55 +0000 | [diff] [blame] | 39 | // + + |
| 40 | // + + |
| 41 | // + + |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 42 | // if.end ("footer"): |
| 43 | // <...> |
| 44 | // |
| 45 | // Diamond shaped code after merge: |
| 46 | // |
| 47 | // header: |
| 48 | // %l = load %addr_l |
| 49 | // br %cond, label %if.then, label %if.else |
Gerolf Hoflehner | ea96a3d | 2014-08-07 23:19:55 +0000 | [diff] [blame] | 50 | // + + |
| 51 | // + + |
| 52 | // + + |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 53 | // if.then: if.else: |
| 54 | // <use %l> <use %l> |
| 55 | // <...> <...> |
| 56 | // br label %if.end br label %if.end |
Gerolf Hoflehner | ea96a3d | 2014-08-07 23:19:55 +0000 | [diff] [blame] | 57 | // + + |
| 58 | // + + |
| 59 | // + + |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 60 | // if.end ("footer"): |
| 61 | // %s.sink = phi [%st, if.then], [%se, if.else] |
| 62 | // <...> |
| 63 | // store %s.sink, %addr_s |
| 64 | // <...> |
| 65 | // |
| 66 | // |
| 67 | //===----------------------- TODO -----------------------------------------===// |
| 68 | // |
| 69 | // 1) Generalize to regions other than diamonds |
| 70 | // 2) Be more aggressive merging memory operations |
| 71 | // Note that both changes require register pressure control |
| 72 | // |
| 73 | //===----------------------------------------------------------------------===// |
| 74 | |
Davide Italiano | b49aa5c | 2016-06-17 19:10:09 +0000 | [diff] [blame^] | 75 | #include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h" |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 76 | #include "llvm/ADT/Statistic.h" |
| 77 | #include "llvm/Analysis/AliasAnalysis.h" |
| 78 | #include "llvm/Analysis/CFG.h" |
Chandler Carruth | 7b560d4 | 2015-09-09 17:55:00 +0000 | [diff] [blame] | 79 | #include "llvm/Analysis/GlobalsModRef.h" |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 80 | #include "llvm/Analysis/Loads.h" |
| 81 | #include "llvm/Analysis/MemoryBuiltins.h" |
| 82 | #include "llvm/Analysis/MemoryDependenceAnalysis.h" |
Eli Friedman | 9f8031c | 2016-06-12 02:11:20 +0000 | [diff] [blame] | 83 | #include "llvm/Analysis/ValueTracking.h" |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 84 | #include "llvm/IR/Metadata.h" |
| 85 | #include "llvm/IR/PatternMatch.h" |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 86 | #include "llvm/Support/Debug.h" |
Benjamin Kramer | b85d375 | 2015-03-23 18:45:56 +0000 | [diff] [blame] | 87 | #include "llvm/Support/raw_ostream.h" |
Mehdi Amini | b550cb1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 88 | #include "llvm/Transforms/Scalar.h" |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 89 | #include "llvm/Transforms/Utils/BasicBlockUtils.h" |
| 90 | #include "llvm/Transforms/Utils/SSAUpdater.h" |
Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 91 | |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 92 | using namespace llvm; |
| 93 | |
| 94 | #define DEBUG_TYPE "mldst-motion" |
| 95 | |
| 96 | //===----------------------------------------------------------------------===// |
| 97 | // MergedLoadStoreMotion Pass |
| 98 | //===----------------------------------------------------------------------===// |
Davide Italiano | b49aa5c | 2016-06-17 19:10:09 +0000 | [diff] [blame^] | 99 | class MergedLoadStoreMotion { |
| 100 | MemoryDependenceResults *MD = nullptr; |
| 101 | AliasAnalysis *AA = nullptr; |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 102 | |
Davide Italiano | b49aa5c | 2016-06-17 19:10:09 +0000 | [diff] [blame^] | 103 | // The mergeLoad/Store algorithms could have Size0 * Size1 complexity, |
| 104 | // where Size0 and Size1 are the #instructions on the two sides of |
| 105 | // the diamond. The constant chosen here is arbitrary. Compiler Time |
| 106 | // Control is enforced by the check Size0 * Size1 < MagicCompileTimeControl. |
| 107 | const int MagicCompileTimeControl = 250; |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 108 | |
| 109 | public: |
Davide Italiano | b49aa5c | 2016-06-17 19:10:09 +0000 | [diff] [blame^] | 110 | bool run(Function &F, MemoryDependenceResults *MD, AliasAnalysis &AA); |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 111 | |
| 112 | private: |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 113 | /// |
| 114 | /// \brief Remove instruction from parent and update memory dependence |
| 115 | /// analysis. |
| 116 | /// |
| 117 | void removeInstruction(Instruction *Inst); |
| 118 | BasicBlock *getDiamondTail(BasicBlock *BB); |
| 119 | bool isDiamondHead(BasicBlock *BB); |
| 120 | // Routines for hoisting loads |
| 121 | bool isLoadHoistBarrierInRange(const Instruction &Start, |
| 122 | const Instruction &End, LoadInst *LI, |
| 123 | bool SafeToLoadUnconditionally); |
| 124 | LoadInst *canHoistFromBlock(BasicBlock *BB, LoadInst *LI); |
| 125 | void hoistInstruction(BasicBlock *BB, Instruction *HoistCand, |
| 126 | Instruction *ElseInst); |
| 127 | bool isSafeToHoist(Instruction *I) const; |
| 128 | bool hoistLoad(BasicBlock *BB, LoadInst *HoistCand, LoadInst *ElseInst); |
| 129 | bool mergeLoads(BasicBlock *BB); |
| 130 | // Routines for sinking stores |
| 131 | StoreInst *canSinkFromBlock(BasicBlock *BB, StoreInst *SI); |
| 132 | PHINode *getPHIOperand(BasicBlock *BB, StoreInst *S0, StoreInst *S1); |
| 133 | bool isStoreSinkBarrierInRange(const Instruction &Start, |
| 134 | const Instruction &End, MemoryLocation Loc); |
| 135 | bool sinkStore(BasicBlock *BB, StoreInst *SinkCand, StoreInst *ElseInst); |
| 136 | bool mergeStores(BasicBlock *BB); |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 139 | /// |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 140 | /// \brief Remove instruction from parent and update memory dependence analysis. |
| 141 | /// |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 142 | void MergedLoadStoreMotion::removeInstruction(Instruction *Inst) { |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 143 | // Notify the memory dependence analysis. |
| 144 | if (MD) { |
| 145 | MD->removeInstruction(Inst); |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 146 | if (auto *LI = dyn_cast<LoadInst>(Inst)) |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 147 | MD->invalidateCachedPointerInfo(LI->getPointerOperand()); |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 148 | if (Inst->getType()->isPtrOrPtrVectorTy()) { |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 149 | MD->invalidateCachedPointerInfo(Inst); |
| 150 | } |
| 151 | } |
| 152 | Inst->eraseFromParent(); |
| 153 | } |
| 154 | |
| 155 | /// |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 156 | /// \brief Return tail block of a diamond. |
| 157 | /// |
| 158 | BasicBlock *MergedLoadStoreMotion::getDiamondTail(BasicBlock *BB) { |
| 159 | assert(isDiamondHead(BB) && "Basic block is not head of a diamond"); |
| 160 | return BB->getTerminator()->getSuccessor(0)->getSingleSuccessor(); |
| 161 | } |
| 162 | |
| 163 | /// |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 164 | /// \brief True when BB is the head of a diamond (hammock) |
| 165 | /// |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 166 | bool MergedLoadStoreMotion::isDiamondHead(BasicBlock *BB) { |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 167 | if (!BB) |
| 168 | return false; |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 169 | auto *BI = dyn_cast<BranchInst>(BB->getTerminator()); |
| 170 | if (!BI || !BI->isConditional()) |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 171 | return false; |
| 172 | |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 173 | BasicBlock *Succ0 = BI->getSuccessor(0); |
| 174 | BasicBlock *Succ1 = BI->getSuccessor(1); |
| 175 | |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 176 | if (!Succ0->getSinglePredecessor()) |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 177 | return false; |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 178 | if (!Succ1->getSinglePredecessor()) |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 179 | return false; |
| 180 | |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 181 | BasicBlock *Succ0Succ = Succ0->getSingleSuccessor(); |
| 182 | BasicBlock *Succ1Succ = Succ1->getSingleSuccessor(); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 183 | // Ignore triangles. |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 184 | if (!Succ0Succ || !Succ1Succ || Succ0Succ != Succ1Succ) |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 185 | return false; |
| 186 | return true; |
| 187 | } |
| 188 | |
| 189 | /// |
| 190 | /// \brief True when instruction is a hoist barrier for a load |
| 191 | /// |
| 192 | /// Whenever an instruction could possibly modify the value |
| 193 | /// being loaded or protect against the load from happening |
| 194 | /// it is considered a hoist barrier. |
| 195 | /// |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 196 | bool MergedLoadStoreMotion::isLoadHoistBarrierInRange( |
| 197 | const Instruction &Start, const Instruction &End, LoadInst *LI, |
| 198 | bool SafeToLoadUnconditionally) { |
David Majnemer | 4745125 | 2016-05-26 07:11:09 +0000 | [diff] [blame] | 199 | if (!SafeToLoadUnconditionally) |
| 200 | for (const Instruction &Inst : |
| 201 | make_range(Start.getIterator(), End.getIterator())) |
Eli Friedman | 9f8031c | 2016-06-12 02:11:20 +0000 | [diff] [blame] | 202 | if (!isGuaranteedToTransferExecutionToSuccessor(&Inst)) |
David Majnemer | 4745125 | 2016-05-26 07:11:09 +0000 | [diff] [blame] | 203 | return true; |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 204 | MemoryLocation Loc = MemoryLocation::get(LI); |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 205 | return AA->canInstructionRangeModRef(Start, End, Loc, MRI_Mod); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /// |
| 209 | /// \brief Decide if a load can be hoisted |
| 210 | /// |
| 211 | /// When there is a load in \p BB to the same address as \p LI |
| 212 | /// and it can be hoisted from \p BB, return that load. |
| 213 | /// Otherwise return Null. |
| 214 | /// |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 215 | LoadInst *MergedLoadStoreMotion::canHoistFromBlock(BasicBlock *BB1, |
| 216 | LoadInst *Load0) { |
David Majnemer | 4745125 | 2016-05-26 07:11:09 +0000 | [diff] [blame] | 217 | BasicBlock *BB0 = Load0->getParent(); |
| 218 | BasicBlock *Head = BB0->getSinglePredecessor(); |
| 219 | bool SafeToLoadUnconditionally = isSafeToLoadUnconditionally( |
| 220 | Load0->getPointerOperand(), Load0->getAlignment(), |
| 221 | Load0->getModule()->getDataLayout(), |
| 222 | /*ScanFrom=*/Head->getTerminator()); |
Elena Demikhovsky | 27152ae | 2014-11-02 08:03:05 +0000 | [diff] [blame] | 223 | for (BasicBlock::iterator BBI = BB1->begin(), BBE = BB1->end(); BBI != BBE; |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 224 | ++BBI) { |
Duncan P. N. Exon Smith | be4d8cb | 2015-10-13 19:26:58 +0000 | [diff] [blame] | 225 | Instruction *Inst = &*BBI; |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 226 | |
| 227 | // Only merge and hoist loads when their result in used only in BB |
David Majnemer | 4745125 | 2016-05-26 07:11:09 +0000 | [diff] [blame] | 228 | auto *Load1 = dyn_cast<LoadInst>(Inst); |
| 229 | if (!Load1 || Inst->isUsedOutsideOfBlock(BB1)) |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 230 | continue; |
| 231 | |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 232 | MemoryLocation Loc0 = MemoryLocation::get(Load0); |
| 233 | MemoryLocation Loc1 = MemoryLocation::get(Load1); |
Chad Rosier | 66a9d07 | 2016-06-14 12:47:18 +0000 | [diff] [blame] | 234 | if (Load0->isSameOperationAs(Load1) && AA->isMustAlias(Loc0, Loc1) && |
David Majnemer | 4745125 | 2016-05-26 07:11:09 +0000 | [diff] [blame] | 235 | !isLoadHoistBarrierInRange(BB1->front(), *Load1, Load1, |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 236 | SafeToLoadUnconditionally) && |
David Majnemer | 4745125 | 2016-05-26 07:11:09 +0000 | [diff] [blame] | 237 | !isLoadHoistBarrierInRange(BB0->front(), *Load0, Load0, |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 238 | SafeToLoadUnconditionally)) { |
Elena Demikhovsky | 27152ae | 2014-11-02 08:03:05 +0000 | [diff] [blame] | 239 | return Load1; |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 240 | } |
| 241 | } |
Elena Demikhovsky | 27152ae | 2014-11-02 08:03:05 +0000 | [diff] [blame] | 242 | return nullptr; |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /// |
| 246 | /// \brief Merge two equivalent instructions \p HoistCand and \p ElseInst into |
| 247 | /// \p BB |
| 248 | /// |
| 249 | /// BB is the head of a diamond |
| 250 | /// |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 251 | void MergedLoadStoreMotion::hoistInstruction(BasicBlock *BB, |
| 252 | Instruction *HoistCand, |
| 253 | Instruction *ElseInst) { |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 254 | DEBUG(dbgs() << " Hoist Instruction into BB \n"; BB->dump(); |
| 255 | dbgs() << "Instruction Left\n"; HoistCand->dump(); dbgs() << "\n"; |
| 256 | dbgs() << "Instruction Right\n"; ElseInst->dump(); dbgs() << "\n"); |
| 257 | // Hoist the instruction. |
| 258 | assert(HoistCand->getParent() != BB); |
| 259 | |
| 260 | // Intersect optional metadata. |
| 261 | HoistCand->intersectOptionalDataWith(ElseInst); |
Adrian Prantl | cbdfdb7 | 2015-08-20 22:00:30 +0000 | [diff] [blame] | 262 | HoistCand->dropUnknownNonDebugMetadata(); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 263 | |
| 264 | // Prepend point for instruction insert |
| 265 | Instruction *HoistPt = BB->getTerminator(); |
| 266 | |
| 267 | // Merged instruction |
| 268 | Instruction *HoistedInst = HoistCand->clone(); |
| 269 | |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 270 | // Hoist instruction. |
| 271 | HoistedInst->insertBefore(HoistPt); |
| 272 | |
| 273 | HoistCand->replaceAllUsesWith(HoistedInst); |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 274 | removeInstruction(HoistCand); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 275 | // Replace the else block instruction. |
| 276 | ElseInst->replaceAllUsesWith(HoistedInst); |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 277 | removeInstruction(ElseInst); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /// |
| 281 | /// \brief Return true if no operand of \p I is defined in I's parent block |
| 282 | /// |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 283 | bool MergedLoadStoreMotion::isSafeToHoist(Instruction *I) const { |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 284 | BasicBlock *Parent = I->getParent(); |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 285 | for (Use &U : I->operands()) |
| 286 | if (auto *Instr = dyn_cast<Instruction>(&U)) |
| 287 | if (Instr->getParent() == Parent) |
| 288 | return false; |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 289 | return true; |
| 290 | } |
| 291 | |
| 292 | /// |
| 293 | /// \brief Merge two equivalent loads and GEPs and hoist into diamond head |
| 294 | /// |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 295 | bool MergedLoadStoreMotion::hoistLoad(BasicBlock *BB, LoadInst *L0, |
| 296 | LoadInst *L1) { |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 297 | // Only one definition? |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 298 | auto *A0 = dyn_cast<Instruction>(L0->getPointerOperand()); |
| 299 | auto *A1 = dyn_cast<Instruction>(L1->getPointerOperand()); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 300 | if (A0 && A1 && A0->isIdenticalTo(A1) && isSafeToHoist(A0) && |
| 301 | A0->hasOneUse() && (A0->getParent() == L0->getParent()) && |
| 302 | A1->hasOneUse() && (A1->getParent() == L1->getParent()) && |
| 303 | isa<GetElementPtrInst>(A0)) { |
| 304 | DEBUG(dbgs() << "Hoist Instruction into BB \n"; BB->dump(); |
| 305 | dbgs() << "Instruction Left\n"; L0->dump(); dbgs() << "\n"; |
| 306 | dbgs() << "Instruction Right\n"; L1->dump(); dbgs() << "\n"); |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 307 | hoistInstruction(BB, A0, A1); |
| 308 | hoistInstruction(BB, L0, L1); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 309 | return true; |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 310 | } |
| 311 | return false; |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /// |
| 315 | /// \brief Try to hoist two loads to same address into diamond header |
| 316 | /// |
| 317 | /// Starting from a diamond head block, iterate over the instructions in one |
| 318 | /// successor block and try to match a load in the second successor. |
| 319 | /// |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 320 | bool MergedLoadStoreMotion::mergeLoads(BasicBlock *BB) { |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 321 | bool MergedLoads = false; |
| 322 | assert(isDiamondHead(BB)); |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 323 | BranchInst *BI = cast<BranchInst>(BB->getTerminator()); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 324 | BasicBlock *Succ0 = BI->getSuccessor(0); |
| 325 | BasicBlock *Succ1 = BI->getSuccessor(1); |
| 326 | // #Instructions in Succ1 for Compile Time Control |
| 327 | int Size1 = Succ1->size(); |
| 328 | int NLoads = 0; |
| 329 | for (BasicBlock::iterator BBI = Succ0->begin(), BBE = Succ0->end(); |
| 330 | BBI != BBE;) { |
Duncan P. N. Exon Smith | be4d8cb | 2015-10-13 19:26:58 +0000 | [diff] [blame] | 331 | Instruction *I = &*BBI; |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 332 | ++BBI; |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 333 | |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 334 | // Don't move non-simple (atomic, volatile) loads. |
| 335 | auto *L0 = dyn_cast<LoadInst>(I); |
Elena Demikhovsky | 27152ae | 2014-11-02 08:03:05 +0000 | [diff] [blame] | 336 | if (!L0 || !L0->isSimple() || L0->isUsedOutsideOfBlock(Succ0)) |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 337 | continue; |
| 338 | |
| 339 | ++NLoads; |
| 340 | if (NLoads * Size1 >= MagicCompileTimeControl) |
| 341 | break; |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 342 | if (LoadInst *L1 = canHoistFromBlock(Succ1, L0)) { |
| 343 | bool Res = hoistLoad(BB, L0, L1); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 344 | MergedLoads |= Res; |
| 345 | // Don't attempt to hoist above loads that had not been hoisted. |
| 346 | if (!Res) |
| 347 | break; |
| 348 | } |
| 349 | } |
| 350 | return MergedLoads; |
| 351 | } |
| 352 | |
| 353 | /// |
Elena Demikhovsky | a5599bf | 2014-12-15 14:09:53 +0000 | [diff] [blame] | 354 | /// \brief True when instruction is a sink barrier for a store |
| 355 | /// located in Loc |
| 356 | /// |
| 357 | /// Whenever an instruction could possibly read or modify the |
| 358 | /// value being stored or protect against the store from |
| 359 | /// happening it is considered a sink barrier. |
| 360 | /// |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 361 | bool MergedLoadStoreMotion::isStoreSinkBarrierInRange(const Instruction &Start, |
| 362 | const Instruction &End, |
| 363 | MemoryLocation Loc) { |
David Majnemer | 4745125 | 2016-05-26 07:11:09 +0000 | [diff] [blame] | 364 | for (const Instruction &Inst : |
| 365 | make_range(Start.getIterator(), End.getIterator())) |
| 366 | if (Inst.mayThrow()) |
| 367 | return true; |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 368 | return AA->canInstructionRangeModRef(Start, End, Loc, MRI_ModRef); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /// |
| 372 | /// \brief Check if \p BB contains a store to the same address as \p SI |
| 373 | /// |
| 374 | /// \return The store in \p when it is safe to sink. Otherwise return Null. |
| 375 | /// |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 376 | StoreInst *MergedLoadStoreMotion::canSinkFromBlock(BasicBlock *BB1, |
| 377 | StoreInst *Store0) { |
Elena Demikhovsky | a5599bf | 2014-12-15 14:09:53 +0000 | [diff] [blame] | 378 | DEBUG(dbgs() << "can Sink? : "; Store0->dump(); dbgs() << "\n"); |
Elena Demikhovsky | ef035bb | 2015-02-17 13:10:05 +0000 | [diff] [blame] | 379 | BasicBlock *BB0 = Store0->getParent(); |
Elena Demikhovsky | a5599bf | 2014-12-15 14:09:53 +0000 | [diff] [blame] | 380 | for (BasicBlock::reverse_iterator RBI = BB1->rbegin(), RBE = BB1->rend(); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 381 | RBI != RBE; ++RBI) { |
| 382 | Instruction *Inst = &*RBI; |
| 383 | |
David Majnemer | 4745125 | 2016-05-26 07:11:09 +0000 | [diff] [blame] | 384 | auto *Store1 = dyn_cast<StoreInst>(Inst); |
| 385 | if (!Store1) |
| 386 | continue; |
Elena Demikhovsky | a5599bf | 2014-12-15 14:09:53 +0000 | [diff] [blame] | 387 | |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 388 | MemoryLocation Loc0 = MemoryLocation::get(Store0); |
| 389 | MemoryLocation Loc1 = MemoryLocation::get(Store1); |
Elena Demikhovsky | a5599bf | 2014-12-15 14:09:53 +0000 | [diff] [blame] | 390 | if (AA->isMustAlias(Loc0, Loc1) && Store0->isSameOperationAs(Store1) && |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 391 | !isStoreSinkBarrierInRange(*Store1->getNextNode(), BB1->back(), Loc1) && |
| 392 | !isStoreSinkBarrierInRange(*Store0->getNextNode(), BB0->back(), Loc0)) { |
Elena Demikhovsky | a5599bf | 2014-12-15 14:09:53 +0000 | [diff] [blame] | 393 | return Store1; |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 394 | } |
| 395 | } |
Elena Demikhovsky | a5599bf | 2014-12-15 14:09:53 +0000 | [diff] [blame] | 396 | return nullptr; |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | /// |
| 400 | /// \brief Create a PHI node in BB for the operands of S0 and S1 |
| 401 | /// |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 402 | PHINode *MergedLoadStoreMotion::getPHIOperand(BasicBlock *BB, StoreInst *S0, |
| 403 | StoreInst *S1) { |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 404 | // Create a phi if the values mismatch. |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 405 | Value *Opd1 = S0->getValueOperand(); |
| 406 | Value *Opd2 = S1->getValueOperand(); |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 407 | if (Opd1 == Opd2) |
| 408 | return nullptr; |
| 409 | |
| 410 | auto *NewPN = PHINode::Create(Opd1->getType(), 2, Opd2->getName() + ".sink", |
| 411 | &BB->front()); |
| 412 | NewPN->addIncoming(Opd1, S0->getParent()); |
| 413 | NewPN->addIncoming(Opd2, S1->getParent()); |
| 414 | if (MD && NewPN->getType()->getScalarType()->isPointerTy()) |
| 415 | MD->invalidateCachedPointerInfo(NewPN); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 416 | return NewPN; |
| 417 | } |
| 418 | |
| 419 | /// |
| 420 | /// \brief Merge two stores to same address and sink into \p BB |
| 421 | /// |
| 422 | /// Also sinks GEP instruction computing the store address |
| 423 | /// |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 424 | bool MergedLoadStoreMotion::sinkStore(BasicBlock *BB, StoreInst *S0, |
| 425 | StoreInst *S1) { |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 426 | // Only one definition? |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 427 | auto *A0 = dyn_cast<Instruction>(S0->getPointerOperand()); |
| 428 | auto *A1 = dyn_cast<Instruction>(S1->getPointerOperand()); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 429 | if (A0 && A1 && A0->isIdenticalTo(A1) && A0->hasOneUse() && |
| 430 | (A0->getParent() == S0->getParent()) && A1->hasOneUse() && |
| 431 | (A1->getParent() == S1->getParent()) && isa<GetElementPtrInst>(A0)) { |
| 432 | DEBUG(dbgs() << "Sink Instruction into BB \n"; BB->dump(); |
| 433 | dbgs() << "Instruction Left\n"; S0->dump(); dbgs() << "\n"; |
| 434 | dbgs() << "Instruction Right\n"; S1->dump(); dbgs() << "\n"); |
| 435 | // Hoist the instruction. |
| 436 | BasicBlock::iterator InsertPt = BB->getFirstInsertionPt(); |
| 437 | // Intersect optional metadata. |
| 438 | S0->intersectOptionalDataWith(S1); |
Adrian Prantl | cbdfdb7 | 2015-08-20 22:00:30 +0000 | [diff] [blame] | 439 | S0->dropUnknownNonDebugMetadata(); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 440 | |
| 441 | // Create the new store to be inserted at the join point. |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 442 | StoreInst *SNew = cast<StoreInst>(S0->clone()); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 443 | Instruction *ANew = A0->clone(); |
Duncan P. N. Exon Smith | be4d8cb | 2015-10-13 19:26:58 +0000 | [diff] [blame] | 444 | SNew->insertBefore(&*InsertPt); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 445 | ANew->insertBefore(SNew); |
| 446 | |
| 447 | assert(S0->getParent() == A0->getParent()); |
| 448 | assert(S1->getParent() == A1->getParent()); |
| 449 | |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 450 | // New PHI operand? Use it. |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 451 | if (PHINode *NewPN = getPHIOperand(BB, S0, S1)) |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 452 | SNew->setOperand(0, NewPN); |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 453 | removeInstruction(S0); |
| 454 | removeInstruction(S1); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 455 | A0->replaceAllUsesWith(ANew); |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 456 | removeInstruction(A0); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 457 | A1->replaceAllUsesWith(ANew); |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 458 | removeInstruction(A1); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 459 | return true; |
| 460 | } |
| 461 | return false; |
| 462 | } |
| 463 | |
| 464 | /// |
| 465 | /// \brief True when two stores are equivalent and can sink into the footer |
| 466 | /// |
| 467 | /// Starting from a diamond tail block, iterate over the instructions in one |
| 468 | /// predecessor block and try to match a store in the second predecessor. |
| 469 | /// |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 470 | bool MergedLoadStoreMotion::mergeStores(BasicBlock *T) { |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 471 | |
| 472 | bool MergedStores = false; |
| 473 | assert(T && "Footer of a diamond cannot be empty"); |
| 474 | |
| 475 | pred_iterator PI = pred_begin(T), E = pred_end(T); |
| 476 | assert(PI != E); |
| 477 | BasicBlock *Pred0 = *PI; |
| 478 | ++PI; |
| 479 | BasicBlock *Pred1 = *PI; |
| 480 | ++PI; |
| 481 | // tail block of a diamond/hammock? |
| 482 | if (Pred0 == Pred1) |
| 483 | return false; // No. |
| 484 | if (PI != E) |
| 485 | return false; // No. More than 2 predecessors. |
| 486 | |
| 487 | // #Instructions in Succ1 for Compile Time Control |
| 488 | int Size1 = Pred1->size(); |
| 489 | int NStores = 0; |
| 490 | |
| 491 | for (BasicBlock::reverse_iterator RBI = Pred0->rbegin(), RBE = Pred0->rend(); |
| 492 | RBI != RBE;) { |
| 493 | |
| 494 | Instruction *I = &*RBI; |
| 495 | ++RBI; |
Elena Demikhovsky | a5599bf | 2014-12-15 14:09:53 +0000 | [diff] [blame] | 496 | |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 497 | // Don't sink non-simple (atomic, volatile) stores. |
| 498 | auto *S0 = dyn_cast<StoreInst>(I); |
| 499 | if (!S0 || !S0->isSimple()) |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 500 | continue; |
| 501 | |
| 502 | ++NStores; |
| 503 | if (NStores * Size1 >= MagicCompileTimeControl) |
| 504 | break; |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 505 | if (StoreInst *S1 = canSinkFromBlock(Pred1, S0)) { |
| 506 | bool Res = sinkStore(T, S0, S1); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 507 | MergedStores |= Res; |
| 508 | // Don't attempt to sink below stores that had to stick around |
| 509 | // But after removal of a store and some of its feeding |
| 510 | // instruction search again from the beginning since the iterator |
| 511 | // is likely stale at this point. |
| 512 | if (!Res) |
| 513 | break; |
David Majnemer | 8cce333 | 2016-05-26 05:43:12 +0000 | [diff] [blame] | 514 | RBI = Pred0->rbegin(); |
| 515 | RBE = Pred0->rend(); |
| 516 | DEBUG(dbgs() << "Search again\n"; Instruction *I = &*RBI; I->dump()); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | return MergedStores; |
| 520 | } |
Hans Wennborg | 083ca9b | 2015-10-06 23:24:35 +0000 | [diff] [blame] | 521 | |
Davide Italiano | b49aa5c | 2016-06-17 19:10:09 +0000 | [diff] [blame^] | 522 | bool MergedLoadStoreMotion::run(Function &F, MemoryDependenceResults *MD, |
| 523 | AliasAnalysis &AA) { |
| 524 | this->MD = MD; |
| 525 | this->AA = &AA; |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 526 | |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 527 | bool Changed = false; |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 528 | DEBUG(dbgs() << "Instruction Merger\n"); |
| 529 | |
| 530 | // Merge unconditional branches, allowing PRE to catch more |
| 531 | // optimization opportunities. |
| 532 | for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE;) { |
Duncan P. N. Exon Smith | be4d8cb | 2015-10-13 19:26:58 +0000 | [diff] [blame] | 533 | BasicBlock *BB = &*FI++; |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 534 | |
| 535 | // Hoist equivalent loads and sink stores |
| 536 | // outside diamonds when possible |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 537 | if (isDiamondHead(BB)) { |
Davide Italiano | 41315f7 | 2016-06-16 17:40:53 +0000 | [diff] [blame] | 538 | Changed |= mergeLoads(BB); |
| 539 | Changed |= mergeStores(getDiamondTail(BB)); |
Gerolf Hoflehner | f27ae6c | 2014-07-18 19:13:09 +0000 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | return Changed; |
| 543 | } |
Davide Italiano | b49aa5c | 2016-06-17 19:10:09 +0000 | [diff] [blame^] | 544 | |
| 545 | namespace { |
| 546 | class MergedLoadStoreMotionLegacyPass : public FunctionPass { |
| 547 | public: |
| 548 | static char ID; // Pass identification, replacement for typeid |
| 549 | MergedLoadStoreMotionLegacyPass() : FunctionPass(ID) { |
| 550 | initializeMergedLoadStoreMotionLegacyPassPass( |
| 551 | *PassRegistry::getPassRegistry()); |
| 552 | } |
| 553 | |
| 554 | /// |
| 555 | /// \brief Run the transformation for each function |
| 556 | /// |
| 557 | bool runOnFunction(Function &F) override { |
| 558 | if (skipFunction(F)) |
| 559 | return false; |
| 560 | MergedLoadStoreMotion Impl; |
| 561 | auto *MDWP = getAnalysisIfAvailable<MemoryDependenceWrapperPass>(); |
| 562 | return Impl.run(F, MDWP ? &MDWP->getMemDep() : nullptr, |
| 563 | getAnalysis<AAResultsWrapperPass>().getAAResults()); |
| 564 | } |
| 565 | |
| 566 | private: |
| 567 | // This transformation requires dominator postdominator info |
| 568 | void getAnalysisUsage(AnalysisUsage &AU) const override { |
| 569 | AU.setPreservesCFG(); |
| 570 | AU.addRequired<AAResultsWrapperPass>(); |
| 571 | AU.addPreserved<GlobalsAAWrapperPass>(); |
| 572 | AU.addPreserved<MemoryDependenceWrapperPass>(); |
| 573 | } |
| 574 | }; |
| 575 | |
| 576 | char MergedLoadStoreMotionLegacyPass::ID = 0; |
| 577 | } // anonymous namespace |
| 578 | |
| 579 | /// |
| 580 | /// \brief createMergedLoadStoreMotionPass - The public interface to this file. |
| 581 | /// |
| 582 | FunctionPass *llvm::createMergedLoadStoreMotionPass() { |
| 583 | return new MergedLoadStoreMotionLegacyPass(); |
| 584 | } |
| 585 | |
| 586 | INITIALIZE_PASS_BEGIN(MergedLoadStoreMotionLegacyPass, "mldst-motion", |
| 587 | "MergedLoadStoreMotion", false, false) |
| 588 | INITIALIZE_PASS_DEPENDENCY(MemoryDependenceWrapperPass) |
| 589 | INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass) |
| 590 | INITIALIZE_PASS_END(MergedLoadStoreMotionLegacyPass, "mldst-motion", |
| 591 | "MergedLoadStoreMotion", false, false) |
| 592 | |
| 593 | PreservedAnalyses |
| 594 | MergedLoadStoreMotionPass::run(Function &F, AnalysisManager<Function> &AM) { |
| 595 | MergedLoadStoreMotion Impl; |
| 596 | auto *MD = AM.getCachedResult<MemoryDependenceAnalysis>(F); |
| 597 | auto &AA = AM.getResult<AAManager>(F); |
| 598 | if (!Impl.run(F, MD, AA)) |
| 599 | return PreservedAnalyses::all(); |
| 600 | |
| 601 | // FIXME: This pass should also 'preserve the CFG'. |
| 602 | // The new pass manager has currently no way to do it. |
| 603 | PreservedAnalyses PA; |
| 604 | PA.preserve<GlobalsAA>(); |
| 605 | PA.preserve<MemoryDependenceAnalysis>(); |
| 606 | return PA; |
| 607 | } |