Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 1 | //===- LoopStrengthReduce.cpp - Strength Reduce GEPs in Loops -------------===// |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Nate Begeman and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 7 | // |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This pass performs a strength reduction on array references inside loops that |
| 11 | // have as one or more of their components the loop induction variable. This is |
| 12 | // accomplished by creating a new Value to hold the initial value of the array |
| 13 | // access for the first iteration, and then creating a new GEP instruction in |
| 14 | // the loop to increment the value by the appropriate amount. |
| 15 | // |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 16 | //===----------------------------------------------------------------------===// |
| 17 | |
Chris Lattner | be3e521 | 2005-08-03 23:30:08 +0000 | [diff] [blame] | 18 | #define DEBUG_TYPE "loop-reduce" |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 19 | #include "llvm/Transforms/Scalar.h" |
| 20 | #include "llvm/Constants.h" |
| 21 | #include "llvm/Instructions.h" |
| 22 | #include "llvm/Type.h" |
Jeff Cohen | 2f3c9b7 | 2005-03-04 04:04:26 +0000 | [diff] [blame] | 23 | #include "llvm/DerivedTypes.h" |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 24 | #include "llvm/Analysis/Dominators.h" |
| 25 | #include "llvm/Analysis/LoopInfo.h" |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 26 | #include "llvm/Analysis/ScalarEvolutionExpander.h" |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 27 | #include "llvm/Support/CFG.h" |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 28 | #include "llvm/Support/GetElementPtrTypeIterator.h" |
Chris Lattner | e0391be | 2005-08-12 22:06:11 +0000 | [diff] [blame] | 29 | #include "llvm/Transforms/Utils/BasicBlockUtils.h" |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 30 | #include "llvm/Transforms/Utils/Local.h" |
Jeff Cohen | 2f3c9b7 | 2005-03-04 04:04:26 +0000 | [diff] [blame] | 31 | #include "llvm/Target/TargetData.h" |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 32 | #include "llvm/ADT/Statistic.h" |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 33 | #include "llvm/Support/Debug.h" |
Jeff Cohen | cfb1d42 | 2005-07-30 18:22:27 +0000 | [diff] [blame] | 34 | #include <algorithm> |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 35 | #include <set> |
| 36 | using namespace llvm; |
| 37 | |
| 38 | namespace { |
| 39 | Statistic<> NumReduced ("loop-reduce", "Number of GEPs strength reduced"); |
Chris Lattner | 26d91f1 | 2005-08-04 22:34:05 +0000 | [diff] [blame] | 40 | Statistic<> NumInserted("loop-reduce", "Number of PHIs inserted"); |
Chris Lattner | 50fad70 | 2005-08-10 00:45:21 +0000 | [diff] [blame] | 41 | Statistic<> NumVariable("loop-reduce","Number of PHIs with variable strides"); |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 42 | |
Chris Lattner | ec3fb63 | 2005-08-03 22:21:05 +0000 | [diff] [blame] | 43 | /// IVStrideUse - Keep track of one use of a strided induction variable, where |
| 44 | /// the stride is stored externally. The Offset member keeps track of the |
| 45 | /// offset from the IV, User is the actual user of the operand, and 'Operand' |
| 46 | /// is the operand # of the User that is the use. |
| 47 | struct IVStrideUse { |
| 48 | SCEVHandle Offset; |
| 49 | Instruction *User; |
| 50 | Value *OperandValToReplace; |
Chris Lattner | 010de25 | 2005-08-08 05:28:22 +0000 | [diff] [blame] | 51 | |
| 52 | // isUseOfPostIncrementedValue - True if this should use the |
| 53 | // post-incremented version of this IV, not the preincremented version. |
| 54 | // This can only be set in special cases, such as the terminating setcc |
Chris Lattner | c6bae65 | 2005-09-12 06:04:47 +0000 | [diff] [blame] | 55 | // instruction for a loop or uses dominated by the loop. |
Chris Lattner | 010de25 | 2005-08-08 05:28:22 +0000 | [diff] [blame] | 56 | bool isUseOfPostIncrementedValue; |
Chris Lattner | ec3fb63 | 2005-08-03 22:21:05 +0000 | [diff] [blame] | 57 | |
| 58 | IVStrideUse(const SCEVHandle &Offs, Instruction *U, Value *O) |
Chris Lattner | 010de25 | 2005-08-08 05:28:22 +0000 | [diff] [blame] | 59 | : Offset(Offs), User(U), OperandValToReplace(O), |
| 60 | isUseOfPostIncrementedValue(false) {} |
Chris Lattner | ec3fb63 | 2005-08-03 22:21:05 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | /// IVUsersOfOneStride - This structure keeps track of all instructions that |
| 64 | /// have an operand that is based on the trip count multiplied by some stride. |
| 65 | /// The stride for all of these users is common and kept external to this |
| 66 | /// structure. |
| 67 | struct IVUsersOfOneStride { |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 68 | /// Users - Keep track of all of the users of this stride as well as the |
Chris Lattner | ec3fb63 | 2005-08-03 22:21:05 +0000 | [diff] [blame] | 69 | /// initial value and the operand that uses the IV. |
| 70 | std::vector<IVStrideUse> Users; |
| 71 | |
| 72 | void addUser(const SCEVHandle &Offset,Instruction *User, Value *Operand) { |
| 73 | Users.push_back(IVStrideUse(Offset, User, Operand)); |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 74 | } |
| 75 | }; |
| 76 | |
| 77 | |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 78 | class LoopStrengthReduce : public FunctionPass { |
| 79 | LoopInfo *LI; |
Chris Lattner | 88cac3d | 2006-01-11 05:10:20 +0000 | [diff] [blame] | 80 | ETForest *EF; |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 81 | ScalarEvolution *SE; |
| 82 | const TargetData *TD; |
| 83 | const Type *UIntPtrTy; |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 84 | bool Changed; |
Chris Lattner | 7e608bb | 2005-08-02 02:52:02 +0000 | [diff] [blame] | 85 | |
| 86 | /// MaxTargetAMSize - This is the maximum power-of-two scale value that the |
| 87 | /// target can handle for free with its addressing modes. |
Jeff Cohen | 2f3c9b7 | 2005-03-04 04:04:26 +0000 | [diff] [blame] | 88 | unsigned MaxTargetAMSize; |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 89 | |
| 90 | /// IVUsesByStride - Keep track of all uses of induction variables that we |
| 91 | /// are interested in. The key of the map is the stride of the access. |
Chris Lattner | 50fad70 | 2005-08-10 00:45:21 +0000 | [diff] [blame] | 92 | std::map<SCEVHandle, IVUsersOfOneStride> IVUsesByStride; |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 93 | |
Chris Lattner | 7305ae2 | 2005-10-09 06:20:55 +0000 | [diff] [blame] | 94 | /// StrideOrder - An ordering of the keys in IVUsesByStride that is stable: |
| 95 | /// We use this to iterate over the IVUsesByStride collection without being |
| 96 | /// dependent on random ordering of pointers in the process. |
| 97 | std::vector<SCEVHandle> StrideOrder; |
| 98 | |
Chris Lattner | 49f72e6 | 2005-08-04 01:19:13 +0000 | [diff] [blame] | 99 | /// CastedValues - As we need to cast values to uintptr_t, this keeps track |
| 100 | /// of the casted version of each value. This is accessed by |
| 101 | /// getCastedVersionOf. |
| 102 | std::map<Value*, Value*> CastedPointers; |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 103 | |
| 104 | /// DeadInsts - Keep track of instructions we may have made dead, so that |
| 105 | /// we can remove them after we are done working. |
| 106 | std::set<Instruction*> DeadInsts; |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 107 | public: |
Jeff Cohen | 2f3c9b7 | 2005-03-04 04:04:26 +0000 | [diff] [blame] | 108 | LoopStrengthReduce(unsigned MTAMS = 1) |
| 109 | : MaxTargetAMSize(MTAMS) { |
| 110 | } |
| 111 | |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 112 | virtual bool runOnFunction(Function &) { |
| 113 | LI = &getAnalysis<LoopInfo>(); |
Chris Lattner | 88cac3d | 2006-01-11 05:10:20 +0000 | [diff] [blame] | 114 | EF = &getAnalysis<ETForest>(); |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 115 | SE = &getAnalysis<ScalarEvolution>(); |
| 116 | TD = &getAnalysis<TargetData>(); |
| 117 | UIntPtrTy = TD->getIntPtrType(); |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 118 | Changed = false; |
| 119 | |
| 120 | for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I) |
| 121 | runOnLoop(*I); |
Chris Lattner | 49f72e6 | 2005-08-04 01:19:13 +0000 | [diff] [blame] | 122 | |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 123 | return Changed; |
| 124 | } |
| 125 | |
| 126 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
Chris Lattner | aa96ae7 | 2005-08-17 06:35:16 +0000 | [diff] [blame] | 127 | // We split critical edges, so we change the CFG. However, we do update |
| 128 | // many analyses if they are around. |
| 129 | AU.addPreservedID(LoopSimplifyID); |
| 130 | AU.addPreserved<LoopInfo>(); |
| 131 | AU.addPreserved<DominatorSet>(); |
Chris Lattner | 88cac3d | 2006-01-11 05:10:20 +0000 | [diff] [blame] | 132 | AU.addPreserved<ETForest>(); |
Chris Lattner | aa96ae7 | 2005-08-17 06:35:16 +0000 | [diff] [blame] | 133 | AU.addPreserved<ImmediateDominators>(); |
| 134 | AU.addPreserved<DominanceFrontier>(); |
| 135 | AU.addPreserved<DominatorTree>(); |
| 136 | |
Jeff Cohen | f465db6 | 2005-02-27 19:37:07 +0000 | [diff] [blame] | 137 | AU.addRequiredID(LoopSimplifyID); |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 138 | AU.addRequired<LoopInfo>(); |
Chris Lattner | 88cac3d | 2006-01-11 05:10:20 +0000 | [diff] [blame] | 139 | AU.addRequired<ETForest>(); |
Jeff Cohen | 2f3c9b7 | 2005-03-04 04:04:26 +0000 | [diff] [blame] | 140 | AU.addRequired<TargetData>(); |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 141 | AU.addRequired<ScalarEvolution>(); |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 142 | } |
Chris Lattner | 49f72e6 | 2005-08-04 01:19:13 +0000 | [diff] [blame] | 143 | |
| 144 | /// getCastedVersionOf - Return the specified value casted to uintptr_t. |
| 145 | /// |
| 146 | Value *getCastedVersionOf(Value *V); |
| 147 | private: |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 148 | void runOnLoop(Loop *L); |
Chris Lattner | 3416e5f | 2005-08-04 17:40:30 +0000 | [diff] [blame] | 149 | bool AddUsersIfInteresting(Instruction *I, Loop *L, |
| 150 | std::set<Instruction*> &Processed); |
| 151 | SCEVHandle GetExpressionSCEV(Instruction *E, Loop *L); |
| 152 | |
Chris Lattner | 010de25 | 2005-08-08 05:28:22 +0000 | [diff] [blame] | 153 | void OptimizeIndvars(Loop *L); |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 154 | |
Chris Lattner | 50fad70 | 2005-08-10 00:45:21 +0000 | [diff] [blame] | 155 | void StrengthReduceStridedIVUsers(const SCEVHandle &Stride, |
| 156 | IVUsersOfOneStride &Uses, |
Chris Lattner | ec3fb63 | 2005-08-03 22:21:05 +0000 | [diff] [blame] | 157 | Loop *L, bool isOnlyStride); |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 158 | void DeleteTriviallyDeadInstructions(std::set<Instruction*> &Insts); |
| 159 | }; |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 160 | RegisterOpt<LoopStrengthReduce> X("loop-reduce", |
Chris Lattner | fe15830 | 2005-09-27 21:10:32 +0000 | [diff] [blame] | 161 | "Loop Strength Reduction"); |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Jeff Cohen | 2f3c9b7 | 2005-03-04 04:04:26 +0000 | [diff] [blame] | 164 | FunctionPass *llvm::createLoopStrengthReducePass(unsigned MaxTargetAMSize) { |
| 165 | return new LoopStrengthReduce(MaxTargetAMSize); |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Chris Lattner | 49f72e6 | 2005-08-04 01:19:13 +0000 | [diff] [blame] | 168 | /// getCastedVersionOf - Return the specified value casted to uintptr_t. |
| 169 | /// |
| 170 | Value *LoopStrengthReduce::getCastedVersionOf(Value *V) { |
| 171 | if (V->getType() == UIntPtrTy) return V; |
| 172 | if (Constant *CB = dyn_cast<Constant>(V)) |
| 173 | return ConstantExpr::getCast(CB, UIntPtrTy); |
| 174 | |
| 175 | Value *&New = CastedPointers[V]; |
| 176 | if (New) return New; |
| 177 | |
| 178 | BasicBlock::iterator InsertPt; |
| 179 | if (Argument *Arg = dyn_cast<Argument>(V)) { |
| 180 | // Insert into the entry of the function, after any allocas. |
| 181 | InsertPt = Arg->getParent()->begin()->begin(); |
| 182 | while (isa<AllocaInst>(InsertPt)) ++InsertPt; |
| 183 | } else { |
| 184 | if (InvokeInst *II = dyn_cast<InvokeInst>(V)) { |
| 185 | InsertPt = II->getNormalDest()->begin(); |
| 186 | } else { |
| 187 | InsertPt = cast<Instruction>(V); |
| 188 | ++InsertPt; |
| 189 | } |
| 190 | |
| 191 | // Do not insert casts into the middle of PHI node blocks. |
| 192 | while (isa<PHINode>(InsertPt)) ++InsertPt; |
| 193 | } |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 194 | |
| 195 | New = new CastInst(V, UIntPtrTy, V->getName(), InsertPt); |
| 196 | DeadInsts.insert(cast<Instruction>(New)); |
| 197 | return New; |
Chris Lattner | 49f72e6 | 2005-08-04 01:19:13 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 201 | /// DeleteTriviallyDeadInstructions - If any of the instructions is the |
| 202 | /// specified set are trivially dead, delete them and see if this makes any of |
| 203 | /// their operands subsequently dead. |
| 204 | void LoopStrengthReduce:: |
| 205 | DeleteTriviallyDeadInstructions(std::set<Instruction*> &Insts) { |
| 206 | while (!Insts.empty()) { |
| 207 | Instruction *I = *Insts.begin(); |
| 208 | Insts.erase(Insts.begin()); |
| 209 | if (isInstructionTriviallyDead(I)) { |
Jeff Cohen | 0456e4a | 2005-03-01 03:46:11 +0000 | [diff] [blame] | 210 | for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) |
| 211 | if (Instruction *U = dyn_cast<Instruction>(I->getOperand(i))) |
| 212 | Insts.insert(U); |
Chris Lattner | 52d83e6 | 2005-08-03 21:36:09 +0000 | [diff] [blame] | 213 | SE->deleteInstructionFromRecords(I); |
| 214 | I->eraseFromParent(); |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 215 | Changed = true; |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
Jeff Cohen | f465db6 | 2005-02-27 19:37:07 +0000 | [diff] [blame] | 220 | |
Chris Lattner | 3416e5f | 2005-08-04 17:40:30 +0000 | [diff] [blame] | 221 | /// GetExpressionSCEV - Compute and return the SCEV for the specified |
| 222 | /// instruction. |
| 223 | SCEVHandle LoopStrengthReduce::GetExpressionSCEV(Instruction *Exp, Loop *L) { |
Chris Lattner | 87265ab | 2005-08-09 23:39:36 +0000 | [diff] [blame] | 224 | // Scalar Evolutions doesn't know how to compute SCEV's for GEP instructions. |
| 225 | // If this is a GEP that SE doesn't know about, compute it now and insert it. |
| 226 | // If this is not a GEP, or if we have already done this computation, just let |
| 227 | // SE figure it out. |
Chris Lattner | 3416e5f | 2005-08-04 17:40:30 +0000 | [diff] [blame] | 228 | GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Exp); |
Chris Lattner | 87265ab | 2005-08-09 23:39:36 +0000 | [diff] [blame] | 229 | if (!GEP || SE->hasSCEV(GEP)) |
Chris Lattner | 3416e5f | 2005-08-04 17:40:30 +0000 | [diff] [blame] | 230 | return SE->getSCEV(Exp); |
| 231 | |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 232 | // Analyze all of the subscripts of this getelementptr instruction, looking |
| 233 | // for uses that are determined by the trip count of L. First, skip all |
| 234 | // operands the are not dependent on the IV. |
| 235 | |
| 236 | // Build up the base expression. Insert an LLVM cast of the pointer to |
| 237 | // uintptr_t first. |
Chris Lattner | 3416e5f | 2005-08-04 17:40:30 +0000 | [diff] [blame] | 238 | SCEVHandle GEPVal = SCEVUnknown::get(getCastedVersionOf(GEP->getOperand(0))); |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 239 | |
| 240 | gep_type_iterator GTI = gep_type_begin(GEP); |
Chris Lattner | 3416e5f | 2005-08-04 17:40:30 +0000 | [diff] [blame] | 241 | |
| 242 | for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i, ++GTI) { |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 243 | // If this is a use of a recurrence that we can analyze, and it comes before |
| 244 | // Op does in the GEP operand list, we will handle this when we process this |
| 245 | // operand. |
| 246 | if (const StructType *STy = dyn_cast<StructType>(*GTI)) { |
| 247 | const StructLayout *SL = TD->getStructLayout(STy); |
| 248 | unsigned Idx = cast<ConstantUInt>(GEP->getOperand(i))->getValue(); |
| 249 | uint64_t Offset = SL->MemberOffsets[Idx]; |
Chris Lattner | 3416e5f | 2005-08-04 17:40:30 +0000 | [diff] [blame] | 250 | GEPVal = SCEVAddExpr::get(GEPVal, |
| 251 | SCEVUnknown::getIntegerSCEV(Offset, UIntPtrTy)); |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 252 | } else { |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 253 | Value *OpVal = getCastedVersionOf(GEP->getOperand(i)); |
| 254 | SCEVHandle Idx = SE->getSCEV(OpVal); |
| 255 | |
Chris Lattner | 3416e5f | 2005-08-04 17:40:30 +0000 | [diff] [blame] | 256 | uint64_t TypeSize = TD->getTypeSize(GTI.getIndexedType()); |
| 257 | if (TypeSize != 1) |
| 258 | Idx = SCEVMulExpr::get(Idx, |
| 259 | SCEVConstant::get(ConstantUInt::get(UIntPtrTy, |
| 260 | TypeSize))); |
| 261 | GEPVal = SCEVAddExpr::get(GEPVal, Idx); |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
Chris Lattner | 87265ab | 2005-08-09 23:39:36 +0000 | [diff] [blame] | 265 | SE->setSCEV(GEP, GEPVal); |
Chris Lattner | 3416e5f | 2005-08-04 17:40:30 +0000 | [diff] [blame] | 266 | return GEPVal; |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 269 | /// getSCEVStartAndStride - Compute the start and stride of this expression, |
| 270 | /// returning false if the expression is not a start/stride pair, or true if it |
| 271 | /// is. The stride must be a loop invariant expression, but the start may be |
| 272 | /// a mix of loop invariant and loop variant expressions. |
| 273 | static bool getSCEVStartAndStride(const SCEVHandle &SH, Loop *L, |
Chris Lattner | 50fad70 | 2005-08-10 00:45:21 +0000 | [diff] [blame] | 274 | SCEVHandle &Start, SCEVHandle &Stride) { |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 275 | SCEVHandle TheAddRec = Start; // Initialize to zero. |
| 276 | |
| 277 | // If the outer level is an AddExpr, the operands are all start values except |
| 278 | // for a nested AddRecExpr. |
| 279 | if (SCEVAddExpr *AE = dyn_cast<SCEVAddExpr>(SH)) { |
| 280 | for (unsigned i = 0, e = AE->getNumOperands(); i != e; ++i) |
| 281 | if (SCEVAddRecExpr *AddRec = |
| 282 | dyn_cast<SCEVAddRecExpr>(AE->getOperand(i))) { |
| 283 | if (AddRec->getLoop() == L) |
| 284 | TheAddRec = SCEVAddExpr::get(AddRec, TheAddRec); |
| 285 | else |
| 286 | return false; // Nested IV of some sort? |
| 287 | } else { |
| 288 | Start = SCEVAddExpr::get(Start, AE->getOperand(i)); |
| 289 | } |
| 290 | |
| 291 | } else if (SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(SH)) { |
| 292 | TheAddRec = SH; |
| 293 | } else { |
| 294 | return false; // not analyzable. |
| 295 | } |
| 296 | |
| 297 | SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(TheAddRec); |
| 298 | if (!AddRec || AddRec->getLoop() != L) return false; |
| 299 | |
| 300 | // FIXME: Generalize to non-affine IV's. |
| 301 | if (!AddRec->isAffine()) return false; |
| 302 | |
| 303 | Start = SCEVAddExpr::get(Start, AddRec->getOperand(0)); |
| 304 | |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 305 | if (!isa<SCEVConstant>(AddRec->getOperand(1))) |
Chris Lattner | 50fad70 | 2005-08-10 00:45:21 +0000 | [diff] [blame] | 306 | DEBUG(std::cerr << "[" << L->getHeader()->getName() |
| 307 | << "] Variable stride: " << *AddRec << "\n"); |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 308 | |
Chris Lattner | 50fad70 | 2005-08-10 00:45:21 +0000 | [diff] [blame] | 309 | Stride = AddRec->getOperand(1); |
| 310 | // Check that all constant strides are the unsigned type, we don't want to |
| 311 | // have two IV's one of signed stride 4 and one of unsigned stride 4 to not be |
| 312 | // merged. |
| 313 | assert((!isa<SCEVConstant>(Stride) || Stride->getType()->isUnsigned()) && |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 314 | "Constants should be canonicalized to unsigned!"); |
Chris Lattner | 50fad70 | 2005-08-10 00:45:21 +0000 | [diff] [blame] | 315 | |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 316 | return true; |
| 317 | } |
| 318 | |
Chris Lattner | 0ae33eb | 2005-10-03 01:04:44 +0000 | [diff] [blame] | 319 | /// IVUseShouldUsePostIncValue - We have discovered a "User" of an IV expression |
| 320 | /// and now we need to decide whether the user should use the preinc or post-inc |
| 321 | /// value. If this user should use the post-inc version of the IV, return true. |
| 322 | /// |
| 323 | /// Choosing wrong here can break dominance properties (if we choose to use the |
| 324 | /// post-inc value when we cannot) or it can end up adding extra live-ranges to |
| 325 | /// the loop, resulting in reg-reg copies (if we use the pre-inc value when we |
| 326 | /// should use the post-inc value). |
| 327 | static bool IVUseShouldUsePostIncValue(Instruction *User, Instruction *IV, |
Chris Lattner | 88cac3d | 2006-01-11 05:10:20 +0000 | [diff] [blame] | 328 | Loop *L, ETForest *EF, Pass *P) { |
Chris Lattner | 0ae33eb | 2005-10-03 01:04:44 +0000 | [diff] [blame] | 329 | // If the user is in the loop, use the preinc value. |
| 330 | if (L->contains(User->getParent())) return false; |
| 331 | |
Chris Lattner | 5e8ca66 | 2005-10-03 02:50:05 +0000 | [diff] [blame] | 332 | BasicBlock *LatchBlock = L->getLoopLatch(); |
| 333 | |
| 334 | // Ok, the user is outside of the loop. If it is dominated by the latch |
| 335 | // block, use the post-inc value. |
Chris Lattner | 88cac3d | 2006-01-11 05:10:20 +0000 | [diff] [blame] | 336 | if (EF->dominates(LatchBlock, User->getParent())) |
Chris Lattner | 5e8ca66 | 2005-10-03 02:50:05 +0000 | [diff] [blame] | 337 | return true; |
| 338 | |
| 339 | // There is one case we have to be careful of: PHI nodes. These little guys |
| 340 | // can live in blocks that do not dominate the latch block, but (since their |
| 341 | // uses occur in the predecessor block, not the block the PHI lives in) should |
| 342 | // still use the post-inc value. Check for this case now. |
| 343 | PHINode *PN = dyn_cast<PHINode>(User); |
| 344 | if (!PN) return false; // not a phi, not dominated by latch block. |
| 345 | |
| 346 | // Look at all of the uses of IV by the PHI node. If any use corresponds to |
| 347 | // a block that is not dominated by the latch block, give up and use the |
| 348 | // preincremented value. |
| 349 | unsigned NumUses = 0; |
| 350 | for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) |
| 351 | if (PN->getIncomingValue(i) == IV) { |
| 352 | ++NumUses; |
Chris Lattner | 88cac3d | 2006-01-11 05:10:20 +0000 | [diff] [blame] | 353 | if (!EF->dominates(LatchBlock, PN->getIncomingBlock(i))) |
Chris Lattner | 5e8ca66 | 2005-10-03 02:50:05 +0000 | [diff] [blame] | 354 | return false; |
| 355 | } |
| 356 | |
| 357 | // Okay, all uses of IV by PN are in predecessor blocks that really are |
| 358 | // dominated by the latch block. Split the critical edges and use the |
| 359 | // post-incremented value. |
| 360 | for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) |
| 361 | if (PN->getIncomingValue(i) == IV) { |
| 362 | SplitCriticalEdge(PN->getIncomingBlock(i), PN->getParent(), P); |
| 363 | if (--NumUses == 0) break; |
| 364 | } |
| 365 | |
| 366 | return true; |
Chris Lattner | 0ae33eb | 2005-10-03 01:04:44 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | |
| 370 | |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 371 | /// AddUsersIfInteresting - Inspect the specified instruction. If it is a |
| 372 | /// reducible SCEV, recursively add its users to the IVUsesByStride set and |
| 373 | /// return true. Otherwise, return false. |
Chris Lattner | 3416e5f | 2005-08-04 17:40:30 +0000 | [diff] [blame] | 374 | bool LoopStrengthReduce::AddUsersIfInteresting(Instruction *I, Loop *L, |
| 375 | std::set<Instruction*> &Processed) { |
Chris Lattner | 63ad796 | 2005-10-21 05:45:41 +0000 | [diff] [blame] | 376 | if (!I->getType()->isInteger() && !isa<PointerType>(I->getType())) |
| 377 | return false; // Void and FP expressions cannot be reduced. |
Chris Lattner | 3416e5f | 2005-08-04 17:40:30 +0000 | [diff] [blame] | 378 | if (!Processed.insert(I).second) |
| 379 | return true; // Instruction already handled. |
| 380 | |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 381 | // Get the symbolic expression for this instruction. |
Chris Lattner | 3416e5f | 2005-08-04 17:40:30 +0000 | [diff] [blame] | 382 | SCEVHandle ISE = GetExpressionSCEV(I, L); |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 383 | if (isa<SCEVCouldNotCompute>(ISE)) return false; |
Chris Lattner | 3416e5f | 2005-08-04 17:40:30 +0000 | [diff] [blame] | 384 | |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 385 | // Get the start and stride for this expression. |
| 386 | SCEVHandle Start = SCEVUnknown::getIntegerSCEV(0, ISE->getType()); |
Chris Lattner | 50fad70 | 2005-08-10 00:45:21 +0000 | [diff] [blame] | 387 | SCEVHandle Stride = Start; |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 388 | if (!getSCEVStartAndStride(ISE, L, Start, Stride)) |
| 389 | return false; // Non-reducible symbolic expression, bail out. |
| 390 | |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 391 | for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); UI != E;++UI){ |
| 392 | Instruction *User = cast<Instruction>(*UI); |
| 393 | |
| 394 | // Do not infinitely recurse on PHI nodes. |
Chris Lattner | 396b2ba | 2005-09-13 02:09:55 +0000 | [diff] [blame] | 395 | if (isa<PHINode>(User) && Processed.count(User)) |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 396 | continue; |
| 397 | |
| 398 | // If this is an instruction defined in a nested loop, or outside this loop, |
Chris Lattner | f918659 | 2005-08-04 00:14:11 +0000 | [diff] [blame] | 399 | // don't recurse into it. |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 400 | bool AddUserToIVUsers = false; |
Chris Lattner | f918659 | 2005-08-04 00:14:11 +0000 | [diff] [blame] | 401 | if (LI->getLoopFor(User->getParent()) != L) { |
Chris Lattner | 396b2ba | 2005-09-13 02:09:55 +0000 | [diff] [blame] | 402 | DEBUG(std::cerr << "FOUND USER in other loop: " << *User |
Chris Lattner | f918659 | 2005-08-04 00:14:11 +0000 | [diff] [blame] | 403 | << " OF SCEV: " << *ISE << "\n"); |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 404 | AddUserToIVUsers = true; |
Chris Lattner | 3416e5f | 2005-08-04 17:40:30 +0000 | [diff] [blame] | 405 | } else if (!AddUsersIfInteresting(User, L, Processed)) { |
Chris Lattner | a4479ad | 2005-08-04 00:40:47 +0000 | [diff] [blame] | 406 | DEBUG(std::cerr << "FOUND USER: " << *User |
| 407 | << " OF SCEV: " << *ISE << "\n"); |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 408 | AddUserToIVUsers = true; |
| 409 | } |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 410 | |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 411 | if (AddUserToIVUsers) { |
Chris Lattner | 7305ae2 | 2005-10-09 06:20:55 +0000 | [diff] [blame] | 412 | IVUsersOfOneStride &StrideUses = IVUsesByStride[Stride]; |
| 413 | if (StrideUses.Users.empty()) // First occurance of this stride? |
| 414 | StrideOrder.push_back(Stride); |
| 415 | |
Chris Lattner | a4479ad | 2005-08-04 00:40:47 +0000 | [diff] [blame] | 416 | // Okay, we found a user that we cannot reduce. Analyze the instruction |
Chris Lattner | c6bae65 | 2005-09-12 06:04:47 +0000 | [diff] [blame] | 417 | // and decide what to do with it. If we are a use inside of the loop, use |
| 418 | // the value before incrementation, otherwise use it after incrementation. |
Chris Lattner | 88cac3d | 2006-01-11 05:10:20 +0000 | [diff] [blame] | 419 | if (IVUseShouldUsePostIncValue(User, I, L, EF, this)) { |
Chris Lattner | c6bae65 | 2005-09-12 06:04:47 +0000 | [diff] [blame] | 420 | // The value used will be incremented by the stride more than we are |
| 421 | // expecting, so subtract this off. |
| 422 | SCEVHandle NewStart = SCEV::getMinusSCEV(Start, Stride); |
Chris Lattner | 7305ae2 | 2005-10-09 06:20:55 +0000 | [diff] [blame] | 423 | StrideUses.addUser(NewStart, User, I); |
| 424 | StrideUses.Users.back().isUseOfPostIncrementedValue = true; |
Chris Lattner | 5e8ca66 | 2005-10-03 02:50:05 +0000 | [diff] [blame] | 425 | DEBUG(std::cerr << " USING POSTINC SCEV, START=" << *NewStart<< "\n"); |
Chris Lattner | 0ae33eb | 2005-10-03 01:04:44 +0000 | [diff] [blame] | 426 | } else { |
Chris Lattner | 7305ae2 | 2005-10-09 06:20:55 +0000 | [diff] [blame] | 427 | StrideUses.addUser(Start, User, I); |
Chris Lattner | c6bae65 | 2005-09-12 06:04:47 +0000 | [diff] [blame] | 428 | } |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | return true; |
| 432 | } |
| 433 | |
| 434 | namespace { |
| 435 | /// BasedUser - For a particular base value, keep information about how we've |
| 436 | /// partitioned the expression so far. |
| 437 | struct BasedUser { |
Chris Lattner | a553b0c | 2005-08-08 22:56:21 +0000 | [diff] [blame] | 438 | /// Base - The Base value for the PHI node that needs to be inserted for |
| 439 | /// this use. As the use is processed, information gets moved from this |
| 440 | /// field to the Imm field (below). BasedUser values are sorted by this |
| 441 | /// field. |
| 442 | SCEVHandle Base; |
| 443 | |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 444 | /// Inst - The instruction using the induction variable. |
| 445 | Instruction *Inst; |
| 446 | |
Chris Lattner | ec3fb63 | 2005-08-03 22:21:05 +0000 | [diff] [blame] | 447 | /// OperandValToReplace - The operand value of Inst to replace with the |
| 448 | /// EmittedBase. |
| 449 | Value *OperandValToReplace; |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 450 | |
| 451 | /// Imm - The immediate value that should be added to the base immediately |
| 452 | /// before Inst, because it will be folded into the imm field of the |
| 453 | /// instruction. |
| 454 | SCEVHandle Imm; |
| 455 | |
| 456 | /// EmittedBase - The actual value* to use for the base value of this |
| 457 | /// operation. This is null if we should just use zero so far. |
| 458 | Value *EmittedBase; |
| 459 | |
Chris Lattner | 010de25 | 2005-08-08 05:28:22 +0000 | [diff] [blame] | 460 | // isUseOfPostIncrementedValue - True if this should use the |
| 461 | // post-incremented version of this IV, not the preincremented version. |
| 462 | // This can only be set in special cases, such as the terminating setcc |
Chris Lattner | c6bae65 | 2005-09-12 06:04:47 +0000 | [diff] [blame] | 463 | // instruction for a loop and uses outside the loop that are dominated by |
| 464 | // the loop. |
Chris Lattner | 010de25 | 2005-08-08 05:28:22 +0000 | [diff] [blame] | 465 | bool isUseOfPostIncrementedValue; |
Chris Lattner | a553b0c | 2005-08-08 22:56:21 +0000 | [diff] [blame] | 466 | |
| 467 | BasedUser(IVStrideUse &IVSU) |
| 468 | : Base(IVSU.Offset), Inst(IVSU.User), |
| 469 | OperandValToReplace(IVSU.OperandValToReplace), |
| 470 | Imm(SCEVUnknown::getIntegerSCEV(0, Base->getType())), EmittedBase(0), |
| 471 | isUseOfPostIncrementedValue(IVSU.isUseOfPostIncrementedValue) {} |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 472 | |
Chris Lattner | 2114b27 | 2005-08-04 20:03:32 +0000 | [diff] [blame] | 473 | // Once we rewrite the code to insert the new IVs we want, update the |
| 474 | // operands of Inst to use the new expression 'NewBase', with 'Imm' added |
| 475 | // to it. |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 476 | void RewriteInstructionToUseNewBase(const SCEVHandle &NewBase, |
Chris Lattner | c60fb08 | 2005-08-12 22:22:17 +0000 | [diff] [blame] | 477 | SCEVExpander &Rewriter, Loop *L, |
| 478 | Pass *P); |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 479 | void dump() const; |
| 480 | }; |
| 481 | } |
| 482 | |
| 483 | void BasedUser::dump() const { |
Chris Lattner | a553b0c | 2005-08-08 22:56:21 +0000 | [diff] [blame] | 484 | std::cerr << " Base=" << *Base; |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 485 | std::cerr << " Imm=" << *Imm; |
| 486 | if (EmittedBase) |
| 487 | std::cerr << " EB=" << *EmittedBase; |
| 488 | |
| 489 | std::cerr << " Inst: " << *Inst; |
| 490 | } |
| 491 | |
Chris Lattner | 2114b27 | 2005-08-04 20:03:32 +0000 | [diff] [blame] | 492 | // Once we rewrite the code to insert the new IVs we want, update the |
| 493 | // operands of Inst to use the new expression 'NewBase', with 'Imm' added |
| 494 | // to it. |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 495 | void BasedUser::RewriteInstructionToUseNewBase(const SCEVHandle &NewBase, |
Chris Lattner | e0391be | 2005-08-12 22:06:11 +0000 | [diff] [blame] | 496 | SCEVExpander &Rewriter, |
Chris Lattner | c60fb08 | 2005-08-12 22:22:17 +0000 | [diff] [blame] | 497 | Loop *L, Pass *P) { |
Chris Lattner | 2114b27 | 2005-08-04 20:03:32 +0000 | [diff] [blame] | 498 | if (!isa<PHINode>(Inst)) { |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 499 | SCEVHandle NewValSCEV = SCEVAddExpr::get(NewBase, Imm); |
Chris Lattner | 2114b27 | 2005-08-04 20:03:32 +0000 | [diff] [blame] | 500 | Value *NewVal = Rewriter.expandCodeFor(NewValSCEV, Inst, |
| 501 | OperandValToReplace->getType()); |
Chris Lattner | 2114b27 | 2005-08-04 20:03:32 +0000 | [diff] [blame] | 502 | // Replace the use of the operand Value with the new Phi we just created. |
| 503 | Inst->replaceUsesOfWith(OperandValToReplace, NewVal); |
| 504 | DEBUG(std::cerr << " CHANGED: IMM =" << *Imm << " Inst = " << *Inst); |
| 505 | return; |
| 506 | } |
| 507 | |
| 508 | // PHI nodes are more complex. We have to insert one copy of the NewBase+Imm |
Chris Lattner | c41e345 | 2005-08-10 00:35:32 +0000 | [diff] [blame] | 509 | // expression into each operand block that uses it. Note that PHI nodes can |
| 510 | // have multiple entries for the same predecessor. We use a map to make sure |
| 511 | // that a PHI node only has a single Value* for each predecessor (which also |
| 512 | // prevents us from inserting duplicate code in some blocks). |
| 513 | std::map<BasicBlock*, Value*> InsertedCode; |
Chris Lattner | 2114b27 | 2005-08-04 20:03:32 +0000 | [diff] [blame] | 514 | PHINode *PN = cast<PHINode>(Inst); |
| 515 | for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { |
| 516 | if (PN->getIncomingValue(i) == OperandValToReplace) { |
Chris Lattner | e0391be | 2005-08-12 22:06:11 +0000 | [diff] [blame] | 517 | // If this is a critical edge, split the edge so that we do not insert the |
Chris Lattner | 396b2ba | 2005-09-13 02:09:55 +0000 | [diff] [blame] | 518 | // code on all predecessor/successor paths. We do this unless this is the |
| 519 | // canonical backedge for this loop, as this can make some inserted code |
| 520 | // be in an illegal position. |
Chris Lattner | 37edbf0 | 2005-10-03 00:31:52 +0000 | [diff] [blame] | 521 | BasicBlock *PHIPred = PN->getIncomingBlock(i); |
| 522 | if (e != 1 && PHIPred->getTerminator()->getNumSuccessors() > 1 && |
| 523 | (PN->getParent() != L->getHeader() || !L->contains(PHIPred))) { |
Chris Lattner | 37edbf0 | 2005-10-03 00:31:52 +0000 | [diff] [blame] | 524 | |
Chris Lattner | aa96ae7 | 2005-08-17 06:35:16 +0000 | [diff] [blame] | 525 | // First step, split the critical edge. |
Chris Lattner | 37edbf0 | 2005-10-03 00:31:52 +0000 | [diff] [blame] | 526 | SplitCriticalEdge(PHIPred, PN->getParent(), P); |
Chris Lattner | c60fb08 | 2005-08-12 22:22:17 +0000 | [diff] [blame] | 527 | |
Chris Lattner | aa96ae7 | 2005-08-17 06:35:16 +0000 | [diff] [blame] | 528 | // Next step: move the basic block. In particular, if the PHI node |
| 529 | // is outside of the loop, and PredTI is in the loop, we want to |
| 530 | // move the block to be immediately before the PHI block, not |
| 531 | // immediately after PredTI. |
Chris Lattner | 37edbf0 | 2005-10-03 00:31:52 +0000 | [diff] [blame] | 532 | if (L->contains(PHIPred) && !L->contains(PN->getParent())) { |
Chris Lattner | aa96ae7 | 2005-08-17 06:35:16 +0000 | [diff] [blame] | 533 | BasicBlock *NewBB = PN->getIncomingBlock(i); |
| 534 | NewBB->moveBefore(PN->getParent()); |
Chris Lattner | e0391be | 2005-08-12 22:06:11 +0000 | [diff] [blame] | 535 | } |
| 536 | } |
Chris Lattner | 2114b27 | 2005-08-04 20:03:32 +0000 | [diff] [blame] | 537 | |
Chris Lattner | c41e345 | 2005-08-10 00:35:32 +0000 | [diff] [blame] | 538 | Value *&Code = InsertedCode[PN->getIncomingBlock(i)]; |
| 539 | if (!Code) { |
| 540 | // Insert the code into the end of the predecessor block. |
| 541 | BasicBlock::iterator InsertPt =PN->getIncomingBlock(i)->getTerminator(); |
Chris Lattner | 2114b27 | 2005-08-04 20:03:32 +0000 | [diff] [blame] | 542 | |
Chris Lattner | c41e345 | 2005-08-10 00:35:32 +0000 | [diff] [blame] | 543 | SCEVHandle NewValSCEV = SCEVAddExpr::get(NewBase, Imm); |
| 544 | Code = Rewriter.expandCodeFor(NewValSCEV, InsertPt, |
| 545 | OperandValToReplace->getType()); |
| 546 | } |
Chris Lattner | 2114b27 | 2005-08-04 20:03:32 +0000 | [diff] [blame] | 547 | |
| 548 | // Replace the use of the operand Value with the new Phi we just created. |
Chris Lattner | c41e345 | 2005-08-10 00:35:32 +0000 | [diff] [blame] | 549 | PN->setIncomingValue(i, Code); |
Chris Lattner | 2114b27 | 2005-08-04 20:03:32 +0000 | [diff] [blame] | 550 | Rewriter.clear(); |
| 551 | } |
| 552 | } |
| 553 | DEBUG(std::cerr << " CHANGED: IMM =" << *Imm << " Inst = " << *Inst); |
| 554 | } |
| 555 | |
| 556 | |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 557 | /// isTargetConstant - Return true if the following can be referenced by the |
| 558 | /// immediate field of a target instruction. |
| 559 | static bool isTargetConstant(const SCEVHandle &V) { |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 560 | |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 561 | // FIXME: Look at the target to decide if &GV is a legal constant immediate. |
Chris Lattner | 3821e47 | 2005-08-08 06:25:50 +0000 | [diff] [blame] | 562 | if (SCEVConstant *SC = dyn_cast<SCEVConstant>(V)) { |
| 563 | // PPC allows a sign-extended 16-bit immediate field. |
Chris Lattner | e08dc62 | 2005-12-05 18:23:57 +0000 | [diff] [blame] | 564 | int64_t V = SC->getValue()->getSExtValue(); |
| 565 | if (V > -(1 << 16) && V < (1 << 16)-1) |
| 566 | return true; |
Chris Lattner | 3821e47 | 2005-08-08 06:25:50 +0000 | [diff] [blame] | 567 | return false; |
| 568 | } |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 569 | |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 570 | return false; // ENABLE this for x86 |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 571 | |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 572 | if (SCEVUnknown *SU = dyn_cast<SCEVUnknown>(V)) |
| 573 | if (ConstantExpr *CE = dyn_cast<ConstantExpr>(SU->getValue())) |
| 574 | if (CE->getOpcode() == Instruction::Cast) |
| 575 | if (isa<GlobalValue>(CE->getOperand(0))) |
| 576 | // FIXME: should check to see that the dest is uintptr_t! |
| 577 | return true; |
| 578 | return false; |
| 579 | } |
| 580 | |
Chris Lattner | 44b807e | 2005-08-08 22:32:34 +0000 | [diff] [blame] | 581 | /// MoveLoopVariantsToImediateField - Move any subexpressions from Val that are |
| 582 | /// loop varying to the Imm operand. |
| 583 | static void MoveLoopVariantsToImediateField(SCEVHandle &Val, SCEVHandle &Imm, |
| 584 | Loop *L) { |
| 585 | if (Val->isLoopInvariant(L)) return; // Nothing to do. |
| 586 | |
| 587 | if (SCEVAddExpr *SAE = dyn_cast<SCEVAddExpr>(Val)) { |
| 588 | std::vector<SCEVHandle> NewOps; |
| 589 | NewOps.reserve(SAE->getNumOperands()); |
| 590 | |
| 591 | for (unsigned i = 0; i != SAE->getNumOperands(); ++i) |
| 592 | if (!SAE->getOperand(i)->isLoopInvariant(L)) { |
| 593 | // If this is a loop-variant expression, it must stay in the immediate |
| 594 | // field of the expression. |
| 595 | Imm = SCEVAddExpr::get(Imm, SAE->getOperand(i)); |
| 596 | } else { |
| 597 | NewOps.push_back(SAE->getOperand(i)); |
| 598 | } |
| 599 | |
| 600 | if (NewOps.empty()) |
| 601 | Val = SCEVUnknown::getIntegerSCEV(0, Val->getType()); |
| 602 | else |
| 603 | Val = SCEVAddExpr::get(NewOps); |
| 604 | } else if (SCEVAddRecExpr *SARE = dyn_cast<SCEVAddRecExpr>(Val)) { |
| 605 | // Try to pull immediates out of the start value of nested addrec's. |
| 606 | SCEVHandle Start = SARE->getStart(); |
| 607 | MoveLoopVariantsToImediateField(Start, Imm, L); |
| 608 | |
| 609 | std::vector<SCEVHandle> Ops(SARE->op_begin(), SARE->op_end()); |
| 610 | Ops[0] = Start; |
| 611 | Val = SCEVAddRecExpr::get(Ops, SARE->getLoop()); |
| 612 | } else { |
| 613 | // Otherwise, all of Val is variant, move the whole thing over. |
| 614 | Imm = SCEVAddExpr::get(Imm, Val); |
| 615 | Val = SCEVUnknown::getIntegerSCEV(0, Val->getType()); |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | |
Chris Lattner | 26d91f1 | 2005-08-04 22:34:05 +0000 | [diff] [blame] | 620 | /// MoveImmediateValues - Look at Val, and pull out any additions of constants |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 621 | /// that can fit into the immediate field of instructions in the target. |
Chris Lattner | 26d91f1 | 2005-08-04 22:34:05 +0000 | [diff] [blame] | 622 | /// Accumulate these immediate values into the Imm value. |
| 623 | static void MoveImmediateValues(SCEVHandle &Val, SCEVHandle &Imm, |
| 624 | bool isAddress, Loop *L) { |
Chris Lattner | 7a65839 | 2005-08-03 23:44:42 +0000 | [diff] [blame] | 625 | if (SCEVAddExpr *SAE = dyn_cast<SCEVAddExpr>(Val)) { |
Chris Lattner | 26d91f1 | 2005-08-04 22:34:05 +0000 | [diff] [blame] | 626 | std::vector<SCEVHandle> NewOps; |
| 627 | NewOps.reserve(SAE->getNumOperands()); |
| 628 | |
| 629 | for (unsigned i = 0; i != SAE->getNumOperands(); ++i) |
Chris Lattner | 7db543f | 2005-08-04 19:08:16 +0000 | [diff] [blame] | 630 | if (isAddress && isTargetConstant(SAE->getOperand(i))) { |
| 631 | Imm = SCEVAddExpr::get(Imm, SAE->getOperand(i)); |
| 632 | } else if (!SAE->getOperand(i)->isLoopInvariant(L)) { |
| 633 | // If this is a loop-variant expression, it must stay in the immediate |
| 634 | // field of the expression. |
| 635 | Imm = SCEVAddExpr::get(Imm, SAE->getOperand(i)); |
Chris Lattner | 26d91f1 | 2005-08-04 22:34:05 +0000 | [diff] [blame] | 636 | } else { |
| 637 | NewOps.push_back(SAE->getOperand(i)); |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 638 | } |
Chris Lattner | 26d91f1 | 2005-08-04 22:34:05 +0000 | [diff] [blame] | 639 | |
| 640 | if (NewOps.empty()) |
| 641 | Val = SCEVUnknown::getIntegerSCEV(0, Val->getType()); |
| 642 | else |
| 643 | Val = SCEVAddExpr::get(NewOps); |
| 644 | return; |
Chris Lattner | 7a65839 | 2005-08-03 23:44:42 +0000 | [diff] [blame] | 645 | } else if (SCEVAddRecExpr *SARE = dyn_cast<SCEVAddRecExpr>(Val)) { |
| 646 | // Try to pull immediates out of the start value of nested addrec's. |
Chris Lattner | 26d91f1 | 2005-08-04 22:34:05 +0000 | [diff] [blame] | 647 | SCEVHandle Start = SARE->getStart(); |
| 648 | MoveImmediateValues(Start, Imm, isAddress, L); |
| 649 | |
| 650 | if (Start != SARE->getStart()) { |
| 651 | std::vector<SCEVHandle> Ops(SARE->op_begin(), SARE->op_end()); |
| 652 | Ops[0] = Start; |
| 653 | Val = SCEVAddRecExpr::get(Ops, SARE->getLoop()); |
| 654 | } |
| 655 | return; |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 656 | } |
| 657 | |
Chris Lattner | 26d91f1 | 2005-08-04 22:34:05 +0000 | [diff] [blame] | 658 | // Loop-variant expressions must stay in the immediate field of the |
| 659 | // expression. |
| 660 | if ((isAddress && isTargetConstant(Val)) || |
| 661 | !Val->isLoopInvariant(L)) { |
| 662 | Imm = SCEVAddExpr::get(Imm, Val); |
| 663 | Val = SCEVUnknown::getIntegerSCEV(0, Val->getType()); |
| 664 | return; |
Chris Lattner | 7a2ca56 | 2005-08-04 19:26:19 +0000 | [diff] [blame] | 665 | } |
Chris Lattner | 26d91f1 | 2005-08-04 22:34:05 +0000 | [diff] [blame] | 666 | |
| 667 | // Otherwise, no immediates to move. |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Chris Lattner | 934520a | 2005-08-13 07:27:18 +0000 | [diff] [blame] | 670 | |
| 671 | /// IncrementAddExprUses - Decompose the specified expression into its added |
| 672 | /// subexpressions, and increment SubExpressionUseCounts for each of these |
| 673 | /// decomposed parts. |
| 674 | static void SeparateSubExprs(std::vector<SCEVHandle> &SubExprs, |
| 675 | SCEVHandle Expr) { |
| 676 | if (SCEVAddExpr *AE = dyn_cast<SCEVAddExpr>(Expr)) { |
| 677 | for (unsigned j = 0, e = AE->getNumOperands(); j != e; ++j) |
| 678 | SeparateSubExprs(SubExprs, AE->getOperand(j)); |
| 679 | } else if (SCEVAddRecExpr *SARE = dyn_cast<SCEVAddRecExpr>(Expr)) { |
| 680 | SCEVHandle Zero = SCEVUnknown::getIntegerSCEV(0, Expr->getType()); |
| 681 | if (SARE->getOperand(0) == Zero) { |
| 682 | SubExprs.push_back(Expr); |
| 683 | } else { |
| 684 | // Compute the addrec with zero as its base. |
| 685 | std::vector<SCEVHandle> Ops(SARE->op_begin(), SARE->op_end()); |
| 686 | Ops[0] = Zero; // Start with zero base. |
| 687 | SubExprs.push_back(SCEVAddRecExpr::get(Ops, SARE->getLoop())); |
| 688 | |
| 689 | |
| 690 | SeparateSubExprs(SubExprs, SARE->getOperand(0)); |
| 691 | } |
| 692 | } else if (!isa<SCEVConstant>(Expr) || |
| 693 | !cast<SCEVConstant>(Expr)->getValue()->isNullValue()) { |
| 694 | // Do not add zero. |
| 695 | SubExprs.push_back(Expr); |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 700 | /// RemoveCommonExpressionsFromUseBases - Look through all of the uses in Bases, |
| 701 | /// removing any common subexpressions from it. Anything truly common is |
| 702 | /// removed, accumulated, and returned. This looks for things like (a+b+c) and |
| 703 | /// (a+c+d) -> (a+c). The common expression is *removed* from the Bases. |
| 704 | static SCEVHandle |
| 705 | RemoveCommonExpressionsFromUseBases(std::vector<BasedUser> &Uses) { |
| 706 | unsigned NumUses = Uses.size(); |
| 707 | |
| 708 | // Only one use? Use its base, regardless of what it is! |
| 709 | SCEVHandle Zero = SCEVUnknown::getIntegerSCEV(0, Uses[0].Base->getType()); |
| 710 | SCEVHandle Result = Zero; |
| 711 | if (NumUses == 1) { |
| 712 | std::swap(Result, Uses[0].Base); |
| 713 | return Result; |
| 714 | } |
| 715 | |
| 716 | // To find common subexpressions, count how many of Uses use each expression. |
| 717 | // If any subexpressions are used Uses.size() times, they are common. |
| 718 | std::map<SCEVHandle, unsigned> SubExpressionUseCounts; |
| 719 | |
Chris Lattner | d6155e9 | 2005-10-11 18:41:04 +0000 | [diff] [blame] | 720 | // UniqueSubExprs - Keep track of all of the subexpressions we see in the |
| 721 | // order we see them. |
| 722 | std::vector<SCEVHandle> UniqueSubExprs; |
| 723 | |
Chris Lattner | 934520a | 2005-08-13 07:27:18 +0000 | [diff] [blame] | 724 | std::vector<SCEVHandle> SubExprs; |
| 725 | for (unsigned i = 0; i != NumUses; ++i) { |
| 726 | // If the base is zero (which is common), return zero now, there are no |
| 727 | // CSEs we can find. |
| 728 | if (Uses[i].Base == Zero) return Zero; |
| 729 | |
| 730 | // Split the expression into subexprs. |
| 731 | SeparateSubExprs(SubExprs, Uses[i].Base); |
| 732 | // Add one to SubExpressionUseCounts for each subexpr present. |
| 733 | for (unsigned j = 0, e = SubExprs.size(); j != e; ++j) |
Chris Lattner | d6155e9 | 2005-10-11 18:41:04 +0000 | [diff] [blame] | 734 | if (++SubExpressionUseCounts[SubExprs[j]] == 1) |
| 735 | UniqueSubExprs.push_back(SubExprs[j]); |
Chris Lattner | 934520a | 2005-08-13 07:27:18 +0000 | [diff] [blame] | 736 | SubExprs.clear(); |
| 737 | } |
| 738 | |
Chris Lattner | d6155e9 | 2005-10-11 18:41:04 +0000 | [diff] [blame] | 739 | // Now that we know how many times each is used, build Result. Iterate over |
| 740 | // UniqueSubexprs so that we have a stable ordering. |
| 741 | for (unsigned i = 0, e = UniqueSubExprs.size(); i != e; ++i) { |
| 742 | std::map<SCEVHandle, unsigned>::iterator I = |
| 743 | SubExpressionUseCounts.find(UniqueSubExprs[i]); |
| 744 | assert(I != SubExpressionUseCounts.end() && "Entry not found?"); |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 745 | if (I->second == NumUses) { // Found CSE! |
| 746 | Result = SCEVAddExpr::get(Result, I->first); |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 747 | } else { |
| 748 | // Remove non-cse's from SubExpressionUseCounts. |
Chris Lattner | d6155e9 | 2005-10-11 18:41:04 +0000 | [diff] [blame] | 749 | SubExpressionUseCounts.erase(I); |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 750 | } |
Chris Lattner | d6155e9 | 2005-10-11 18:41:04 +0000 | [diff] [blame] | 751 | } |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 752 | |
| 753 | // If we found no CSE's, return now. |
| 754 | if (Result == Zero) return Result; |
| 755 | |
| 756 | // Otherwise, remove all of the CSE's we found from each of the base values. |
Chris Lattner | 934520a | 2005-08-13 07:27:18 +0000 | [diff] [blame] | 757 | for (unsigned i = 0; i != NumUses; ++i) { |
| 758 | // Split the expression into subexprs. |
| 759 | SeparateSubExprs(SubExprs, Uses[i].Base); |
| 760 | |
| 761 | // Remove any common subexpressions. |
| 762 | for (unsigned j = 0, e = SubExprs.size(); j != e; ++j) |
| 763 | if (SubExpressionUseCounts.count(SubExprs[j])) { |
| 764 | SubExprs.erase(SubExprs.begin()+j); |
| 765 | --j; --e; |
| 766 | } |
| 767 | |
| 768 | // Finally, the non-shared expressions together. |
| 769 | if (SubExprs.empty()) |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 770 | Uses[i].Base = Zero; |
Chris Lattner | 934520a | 2005-08-13 07:27:18 +0000 | [diff] [blame] | 771 | else |
| 772 | Uses[i].Base = SCEVAddExpr::get(SubExprs); |
Chris Lattner | 27e5142 | 2005-08-13 07:42:01 +0000 | [diff] [blame] | 773 | SubExprs.clear(); |
Chris Lattner | 934520a | 2005-08-13 07:27:18 +0000 | [diff] [blame] | 774 | } |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 775 | |
| 776 | return Result; |
| 777 | } |
| 778 | |
| 779 | |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 780 | /// StrengthReduceStridedIVUsers - Strength reduce all of the users of a single |
| 781 | /// stride of IV. All of the users may have different starting values, and this |
| 782 | /// may not be the only stride (we know it is if isOnlyStride is true). |
Chris Lattner | 50fad70 | 2005-08-10 00:45:21 +0000 | [diff] [blame] | 783 | void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride, |
Chris Lattner | ec3fb63 | 2005-08-03 22:21:05 +0000 | [diff] [blame] | 784 | IVUsersOfOneStride &Uses, |
| 785 | Loop *L, |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 786 | bool isOnlyStride) { |
| 787 | // Transform our list of users and offsets to a bit more complex table. In |
Chris Lattner | a553b0c | 2005-08-08 22:56:21 +0000 | [diff] [blame] | 788 | // this new vector, each 'BasedUser' contains 'Base' the base of the |
| 789 | // strided accessas well as the old information from Uses. We progressively |
| 790 | // move information from the Base field to the Imm field, until we eventually |
| 791 | // have the full access expression to rewrite the use. |
| 792 | std::vector<BasedUser> UsersToProcess; |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 793 | UsersToProcess.reserve(Uses.Users.size()); |
Chris Lattner | a553b0c | 2005-08-08 22:56:21 +0000 | [diff] [blame] | 794 | for (unsigned i = 0, e = Uses.Users.size(); i != e; ++i) { |
| 795 | UsersToProcess.push_back(Uses.Users[i]); |
| 796 | |
| 797 | // Move any loop invariant operands from the offset field to the immediate |
| 798 | // field of the use, so that we don't try to use something before it is |
| 799 | // computed. |
| 800 | MoveLoopVariantsToImediateField(UsersToProcess.back().Base, |
| 801 | UsersToProcess.back().Imm, L); |
| 802 | assert(UsersToProcess.back().Base->isLoopInvariant(L) && |
Chris Lattner | 26d91f1 | 2005-08-04 22:34:05 +0000 | [diff] [blame] | 803 | "Base value is not loop invariant!"); |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 804 | } |
Chris Lattner | 44b807e | 2005-08-08 22:32:34 +0000 | [diff] [blame] | 805 | |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 806 | // We now have a whole bunch of uses of like-strided induction variables, but |
| 807 | // they might all have different bases. We want to emit one PHI node for this |
| 808 | // stride which we fold as many common expressions (between the IVs) into as |
| 809 | // possible. Start by identifying the common expressions in the base values |
| 810 | // for the strides (e.g. if we have "A+C+B" and "A+B+D" as our bases, find |
| 811 | // "A+B"), emit it to the preheader, then remove the expression from the |
| 812 | // UsersToProcess base values. |
| 813 | SCEVHandle CommonExprs = RemoveCommonExpressionsFromUseBases(UsersToProcess); |
| 814 | |
Chris Lattner | 44b807e | 2005-08-08 22:32:34 +0000 | [diff] [blame] | 815 | // Next, figure out what we can represent in the immediate fields of |
| 816 | // instructions. If we can represent anything there, move it to the imm |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 817 | // fields of the BasedUsers. We do this so that it increases the commonality |
| 818 | // of the remaining uses. |
Chris Lattner | 44b807e | 2005-08-08 22:32:34 +0000 | [diff] [blame] | 819 | for (unsigned i = 0, e = UsersToProcess.size(); i != e; ++i) { |
Chris Lattner | 80b32b3 | 2005-08-16 00:38:11 +0000 | [diff] [blame] | 820 | // If the user is not in the current loop, this means it is using the exit |
| 821 | // value of the IV. Do not put anything in the base, make sure it's all in |
| 822 | // the immediate field to allow as much factoring as possible. |
| 823 | if (!L->contains(UsersToProcess[i].Inst->getParent())) { |
Chris Lattner | 8385e51 | 2005-08-17 21:22:41 +0000 | [diff] [blame] | 824 | UsersToProcess[i].Imm = SCEVAddExpr::get(UsersToProcess[i].Imm, |
| 825 | UsersToProcess[i].Base); |
| 826 | UsersToProcess[i].Base = |
| 827 | SCEVUnknown::getIntegerSCEV(0, UsersToProcess[i].Base->getType()); |
Chris Lattner | 80b32b3 | 2005-08-16 00:38:11 +0000 | [diff] [blame] | 828 | } else { |
| 829 | |
| 830 | // Addressing modes can be folded into loads and stores. Be careful that |
| 831 | // the store is through the expression, not of the expression though. |
| 832 | bool isAddress = isa<LoadInst>(UsersToProcess[i].Inst); |
| 833 | if (StoreInst *SI = dyn_cast<StoreInst>(UsersToProcess[i].Inst)) |
| 834 | if (SI->getOperand(1) == UsersToProcess[i].OperandValToReplace) |
| 835 | isAddress = true; |
| 836 | |
| 837 | MoveImmediateValues(UsersToProcess[i].Base, UsersToProcess[i].Imm, |
| 838 | isAddress, L); |
| 839 | } |
Chris Lattner | 44b807e | 2005-08-08 22:32:34 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 842 | // Now that we know what we need to do, insert the PHI node itself. |
| 843 | // |
| 844 | DEBUG(std::cerr << "INSERTING IV of STRIDE " << *Stride << " and BASE " |
| 845 | << *CommonExprs << " :\n"); |
| 846 | |
| 847 | SCEVExpander Rewriter(*SE, *LI); |
| 848 | SCEVExpander PreheaderRewriter(*SE, *LI); |
Chris Lattner | 44b807e | 2005-08-08 22:32:34 +0000 | [diff] [blame] | 849 | |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 850 | BasicBlock *Preheader = L->getLoopPreheader(); |
| 851 | Instruction *PreInsertPt = Preheader->getTerminator(); |
| 852 | Instruction *PhiInsertBefore = L->getHeader()->begin(); |
Chris Lattner | 44b807e | 2005-08-08 22:32:34 +0000 | [diff] [blame] | 853 | |
Chris Lattner | 12b5041 | 2005-09-12 17:11:27 +0000 | [diff] [blame] | 854 | BasicBlock *LatchBlock = L->getLoopLatch(); |
Chris Lattner | be3e521 | 2005-08-03 23:30:08 +0000 | [diff] [blame] | 855 | |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 856 | // Create a new Phi for this base, and stick it in the loop header. |
| 857 | const Type *ReplacedTy = CommonExprs->getType(); |
| 858 | PHINode *NewPHI = new PHINode(ReplacedTy, "iv.", PhiInsertBefore); |
| 859 | ++NumInserted; |
| 860 | |
Chris Lattner | 50fad70 | 2005-08-10 00:45:21 +0000 | [diff] [blame] | 861 | // Insert the stride into the preheader. |
| 862 | Value *StrideV = PreheaderRewriter.expandCodeFor(Stride, PreInsertPt, |
| 863 | ReplacedTy); |
| 864 | if (!isa<ConstantInt>(StrideV)) ++NumVariable; |
| 865 | |
| 866 | |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 867 | // Emit the initial base value into the loop preheader, and add it to the |
| 868 | // Phi node. |
| 869 | Value *PHIBaseV = PreheaderRewriter.expandCodeFor(CommonExprs, PreInsertPt, |
| 870 | ReplacedTy); |
| 871 | NewPHI->addIncoming(PHIBaseV, Preheader); |
| 872 | |
| 873 | // Emit the increment of the base value before the terminator of the loop |
| 874 | // latch block, and add it to the Phi node. |
| 875 | SCEVHandle IncExp = SCEVAddExpr::get(SCEVUnknown::get(NewPHI), |
Chris Lattner | 50fad70 | 2005-08-10 00:45:21 +0000 | [diff] [blame] | 876 | SCEVUnknown::get(StrideV)); |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 877 | |
| 878 | Value *IncV = Rewriter.expandCodeFor(IncExp, LatchBlock->getTerminator(), |
| 879 | ReplacedTy); |
| 880 | IncV->setName(NewPHI->getName()+".inc"); |
| 881 | NewPHI->addIncoming(IncV, LatchBlock); |
| 882 | |
Chris Lattner | 2351aba | 2005-08-03 22:51:21 +0000 | [diff] [blame] | 883 | // Sort by the base value, so that all IVs with identical bases are next to |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 884 | // each other. |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 885 | while (!UsersToProcess.empty()) { |
Chris Lattner | 7b445c5 | 2005-10-11 18:30:57 +0000 | [diff] [blame] | 886 | SCEVHandle Base = UsersToProcess.back().Base; |
Chris Lattner | be3e521 | 2005-08-03 23:30:08 +0000 | [diff] [blame] | 887 | |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 888 | DEBUG(std::cerr << " INSERTING code for BASE = " << *Base << ":\n"); |
Chris Lattner | be3e521 | 2005-08-03 23:30:08 +0000 | [diff] [blame] | 889 | |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 890 | // Emit the code for Base into the preheader. |
Chris Lattner | 5272f3c | 2005-08-08 05:47:49 +0000 | [diff] [blame] | 891 | Value *BaseV = PreheaderRewriter.expandCodeFor(Base, PreInsertPt, |
| 892 | ReplacedTy); |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 893 | |
| 894 | // If BaseV is a constant other than 0, make sure that it gets inserted into |
| 895 | // the preheader, instead of being forward substituted into the uses. We do |
| 896 | // this by forcing a noop cast to be inserted into the preheader in this |
| 897 | // case. |
| 898 | if (Constant *C = dyn_cast<Constant>(BaseV)) |
Chris Lattner | 7259df3 | 2005-09-10 01:18:45 +0000 | [diff] [blame] | 899 | if (!C->isNullValue() && !isTargetConstant(Base)) { |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 900 | // We want this constant emitted into the preheader! |
| 901 | BaseV = new CastInst(BaseV, BaseV->getType(), "preheaderinsert", |
| 902 | PreInsertPt); |
| 903 | } |
| 904 | |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 905 | // Emit the code to add the immediate offset to the Phi value, just before |
Chris Lattner | 2351aba | 2005-08-03 22:51:21 +0000 | [diff] [blame] | 906 | // the instructions that we identified as using this stride and base. |
Chris Lattner | 7b445c5 | 2005-10-11 18:30:57 +0000 | [diff] [blame] | 907 | unsigned ScanPos = 0; |
| 908 | do { |
| 909 | BasedUser &User = UsersToProcess.back(); |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 910 | |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 911 | // If this instruction wants to use the post-incremented value, move it |
| 912 | // after the post-inc and use its value instead of the PHI. |
| 913 | Value *RewriteOp = NewPHI; |
| 914 | if (User.isUseOfPostIncrementedValue) { |
| 915 | RewriteOp = IncV; |
Chris Lattner | c6bae65 | 2005-09-12 06:04:47 +0000 | [diff] [blame] | 916 | |
| 917 | // If this user is in the loop, make sure it is the last thing in the |
| 918 | // loop to ensure it is dominated by the increment. |
| 919 | if (L->contains(User.Inst->getParent())) |
| 920 | User.Inst->moveBefore(LatchBlock->getTerminator()); |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 921 | } |
| 922 | SCEVHandle RewriteExpr = SCEVUnknown::get(RewriteOp); |
| 923 | |
Chris Lattner | 2351aba | 2005-08-03 22:51:21 +0000 | [diff] [blame] | 924 | // Clear the SCEVExpander's expression map so that we are guaranteed |
| 925 | // to have the code emitted where we expect it. |
| 926 | Rewriter.clear(); |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 927 | |
Chris Lattner | 2114b27 | 2005-08-04 20:03:32 +0000 | [diff] [blame] | 928 | // Now that we know what we need to do, insert code before User for the |
| 929 | // immediate and any loop-variant expressions. |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 930 | if (!isa<ConstantInt>(BaseV) || !cast<ConstantInt>(BaseV)->isNullValue()) |
| 931 | // Add BaseV to the PHI value if needed. |
| 932 | RewriteExpr = SCEVAddExpr::get(RewriteExpr, SCEVUnknown::get(BaseV)); |
| 933 | |
Chris Lattner | c60fb08 | 2005-08-12 22:22:17 +0000 | [diff] [blame] | 934 | User.RewriteInstructionToUseNewBase(RewriteExpr, Rewriter, L, this); |
Jeff Cohen | d29b6aa | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 935 | |
Chris Lattner | 2351aba | 2005-08-03 22:51:21 +0000 | [diff] [blame] | 936 | // Mark old value we replaced as possibly dead, so that it is elminated |
| 937 | // if we just replaced the last use of that value. |
Chris Lattner | 2114b27 | 2005-08-04 20:03:32 +0000 | [diff] [blame] | 938 | DeadInsts.insert(cast<Instruction>(User.OperandValToReplace)); |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 939 | |
Chris Lattner | 7b445c5 | 2005-10-11 18:30:57 +0000 | [diff] [blame] | 940 | UsersToProcess.pop_back(); |
Chris Lattner | 2351aba | 2005-08-03 22:51:21 +0000 | [diff] [blame] | 941 | ++NumReduced; |
Chris Lattner | 7b445c5 | 2005-10-11 18:30:57 +0000 | [diff] [blame] | 942 | |
| 943 | // If there are any more users to process with the same base, move one of |
| 944 | // them to the end of the list so that we will process it. |
| 945 | if (!UsersToProcess.empty()) { |
| 946 | for (unsigned e = UsersToProcess.size(); ScanPos != e; ++ScanPos) |
| 947 | if (UsersToProcess[ScanPos].Base == Base) { |
| 948 | std::swap(UsersToProcess[ScanPos], UsersToProcess.back()); |
| 949 | break; |
| 950 | } |
| 951 | } |
| 952 | } while (!UsersToProcess.empty() && UsersToProcess.back().Base == Base); |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 953 | // TODO: Next, find out which base index is the most common, pull it out. |
| 954 | } |
| 955 | |
| 956 | // IMPORTANT TODO: Figure out how to partition the IV's with this stride, but |
| 957 | // different starting values, into different PHIs. |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 958 | } |
| 959 | |
Chris Lattner | 010de25 | 2005-08-08 05:28:22 +0000 | [diff] [blame] | 960 | // OptimizeIndvars - Now that IVUsesByStride is set up with all of the indvar |
| 961 | // uses in the loop, look to see if we can eliminate some, in favor of using |
| 962 | // common indvars for the different uses. |
| 963 | void LoopStrengthReduce::OptimizeIndvars(Loop *L) { |
| 964 | // TODO: implement optzns here. |
| 965 | |
| 966 | |
| 967 | |
| 968 | |
| 969 | // Finally, get the terminating condition for the loop if possible. If we |
| 970 | // can, we want to change it to use a post-incremented version of its |
| 971 | // induction variable, to allow coallescing the live ranges for the IV into |
| 972 | // one register value. |
| 973 | PHINode *SomePHI = cast<PHINode>(L->getHeader()->begin()); |
| 974 | BasicBlock *Preheader = L->getLoopPreheader(); |
| 975 | BasicBlock *LatchBlock = |
| 976 | SomePHI->getIncomingBlock(SomePHI->getIncomingBlock(0) == Preheader); |
| 977 | BranchInst *TermBr = dyn_cast<BranchInst>(LatchBlock->getTerminator()); |
| 978 | if (!TermBr || TermBr->isUnconditional() || |
| 979 | !isa<SetCondInst>(TermBr->getCondition())) |
| 980 | return; |
| 981 | SetCondInst *Cond = cast<SetCondInst>(TermBr->getCondition()); |
| 982 | |
| 983 | // Search IVUsesByStride to find Cond's IVUse if there is one. |
| 984 | IVStrideUse *CondUse = 0; |
Chris Lattner | 50fad70 | 2005-08-10 00:45:21 +0000 | [diff] [blame] | 985 | const SCEVHandle *CondStride = 0; |
Chris Lattner | 010de25 | 2005-08-08 05:28:22 +0000 | [diff] [blame] | 986 | |
Chris Lattner | b4dd1b8 | 2005-10-11 18:17:57 +0000 | [diff] [blame] | 987 | for (unsigned Stride = 0, e = StrideOrder.size(); Stride != e && !CondUse; |
| 988 | ++Stride) { |
| 989 | std::map<SCEVHandle, IVUsersOfOneStride>::iterator SI = |
| 990 | IVUsesByStride.find(StrideOrder[Stride]); |
| 991 | assert(SI != IVUsesByStride.end() && "Stride doesn't exist!"); |
| 992 | |
| 993 | for (std::vector<IVStrideUse>::iterator UI = SI->second.Users.begin(), |
| 994 | E = SI->second.Users.end(); UI != E; ++UI) |
Chris Lattner | 010de25 | 2005-08-08 05:28:22 +0000 | [diff] [blame] | 995 | if (UI->User == Cond) { |
| 996 | CondUse = &*UI; |
Chris Lattner | b4dd1b8 | 2005-10-11 18:17:57 +0000 | [diff] [blame] | 997 | CondStride = &SI->first; |
Chris Lattner | 010de25 | 2005-08-08 05:28:22 +0000 | [diff] [blame] | 998 | // NOTE: we could handle setcc instructions with multiple uses here, but |
| 999 | // InstCombine does it as well for simple uses, it's not clear that it |
| 1000 | // occurs enough in real life to handle. |
| 1001 | break; |
| 1002 | } |
Chris Lattner | b4dd1b8 | 2005-10-11 18:17:57 +0000 | [diff] [blame] | 1003 | } |
Chris Lattner | 010de25 | 2005-08-08 05:28:22 +0000 | [diff] [blame] | 1004 | if (!CondUse) return; // setcc doesn't use the IV. |
| 1005 | |
| 1006 | // setcc stride is complex, don't mess with users. |
Chris Lattner | 50fad70 | 2005-08-10 00:45:21 +0000 | [diff] [blame] | 1007 | // FIXME: Evaluate whether this is a good idea or not. |
| 1008 | if (!isa<SCEVConstant>(*CondStride)) return; |
Chris Lattner | 010de25 | 2005-08-08 05:28:22 +0000 | [diff] [blame] | 1009 | |
| 1010 | // It's possible for the setcc instruction to be anywhere in the loop, and |
| 1011 | // possible for it to have multiple users. If it is not immediately before |
| 1012 | // the latch block branch, move it. |
| 1013 | if (&*++BasicBlock::iterator(Cond) != (Instruction*)TermBr) { |
| 1014 | if (Cond->hasOneUse()) { // Condition has a single use, just move it. |
| 1015 | Cond->moveBefore(TermBr); |
| 1016 | } else { |
| 1017 | // Otherwise, clone the terminating condition and insert into the loopend. |
| 1018 | Cond = cast<SetCondInst>(Cond->clone()); |
| 1019 | Cond->setName(L->getHeader()->getName() + ".termcond"); |
| 1020 | LatchBlock->getInstList().insert(TermBr, Cond); |
| 1021 | |
| 1022 | // Clone the IVUse, as the old use still exists! |
Chris Lattner | 50fad70 | 2005-08-10 00:45:21 +0000 | [diff] [blame] | 1023 | IVUsesByStride[*CondStride].addUser(CondUse->Offset, Cond, |
Chris Lattner | 010de25 | 2005-08-08 05:28:22 +0000 | [diff] [blame] | 1024 | CondUse->OperandValToReplace); |
Chris Lattner | 50fad70 | 2005-08-10 00:45:21 +0000 | [diff] [blame] | 1025 | CondUse = &IVUsesByStride[*CondStride].Users.back(); |
Chris Lattner | 010de25 | 2005-08-08 05:28:22 +0000 | [diff] [blame] | 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | // If we get to here, we know that we can transform the setcc instruction to |
| 1030 | // use the post-incremented version of the IV, allowing us to coallesce the |
| 1031 | // live ranges for the IV correctly. |
Chris Lattner | 50fad70 | 2005-08-10 00:45:21 +0000 | [diff] [blame] | 1032 | CondUse->Offset = SCEV::getMinusSCEV(CondUse->Offset, *CondStride); |
Chris Lattner | 010de25 | 2005-08-08 05:28:22 +0000 | [diff] [blame] | 1033 | CondUse->isUseOfPostIncrementedValue = true; |
| 1034 | } |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 1035 | |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 1036 | void LoopStrengthReduce::runOnLoop(Loop *L) { |
| 1037 | // First step, transform all loops nesting inside of this loop. |
| 1038 | for (LoopInfo::iterator I = L->begin(), E = L->end(); I != E; ++I) |
| 1039 | runOnLoop(*I); |
| 1040 | |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 1041 | // Next, find all uses of induction variables in this loop, and catagorize |
| 1042 | // them by stride. Start by finding all of the PHI nodes in the header for |
| 1043 | // this loop. If they are induction variables, inspect their uses. |
Chris Lattner | 3416e5f | 2005-08-04 17:40:30 +0000 | [diff] [blame] | 1044 | std::set<Instruction*> Processed; // Don't reprocess instructions. |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 1045 | for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ++I) |
Chris Lattner | 3416e5f | 2005-08-04 17:40:30 +0000 | [diff] [blame] | 1046 | AddUsersIfInteresting(I, L, Processed); |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 1047 | |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 1048 | // If we have nothing to do, return. |
Chris Lattner | 010de25 | 2005-08-08 05:28:22 +0000 | [diff] [blame] | 1049 | if (IVUsesByStride.empty()) return; |
| 1050 | |
| 1051 | // Optimize induction variables. Some indvar uses can be transformed to use |
| 1052 | // strides that will be needed for other purposes. A common example of this |
| 1053 | // is the exit test for the loop, which can often be rewritten to use the |
| 1054 | // computation of some other indvar to decide when to terminate the loop. |
| 1055 | OptimizeIndvars(L); |
| 1056 | |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1057 | |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 1058 | // FIXME: We can widen subreg IV's here for RISC targets. e.g. instead of |
| 1059 | // doing computation in byte values, promote to 32-bit values if safe. |
| 1060 | |
| 1061 | // FIXME: Attempt to reuse values across multiple IV's. In particular, we |
| 1062 | // could have something like "for(i) { foo(i*8); bar(i*16) }", which should be |
| 1063 | // codegened as "for (j = 0;; j+=8) { foo(j); bar(j+j); }" on X86/PPC. Need |
| 1064 | // to be careful that IV's are all the same type. Only works for intptr_t |
| 1065 | // indvars. |
| 1066 | |
| 1067 | // If we only have one stride, we can more aggressively eliminate some things. |
| 1068 | bool HasOneStride = IVUsesByStride.size() == 1; |
Chris Lattner | 7305ae2 | 2005-10-09 06:20:55 +0000 | [diff] [blame] | 1069 | |
Chris Lattner | 1bbae0c | 2005-08-09 00:18:09 +0000 | [diff] [blame] | 1070 | // Note: this processes each stride/type pair individually. All users passed |
Chris Lattner | 7305ae2 | 2005-10-09 06:20:55 +0000 | [diff] [blame] | 1071 | // into StrengthReduceStridedIVUsers have the same type AND stride. Also, |
| 1072 | // node that we iterate over IVUsesByStride indirectly by using StrideOrder. |
| 1073 | // This extra layer of indirection makes the ordering of strides deterministic |
| 1074 | // - not dependent on map order. |
| 1075 | for (unsigned Stride = 0, e = StrideOrder.size(); Stride != e; ++Stride) { |
| 1076 | std::map<SCEVHandle, IVUsersOfOneStride>::iterator SI = |
| 1077 | IVUsesByStride.find(StrideOrder[Stride]); |
| 1078 | assert(SI != IVUsesByStride.end() && "Stride doesn't exist!"); |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 1079 | StrengthReduceStridedIVUsers(SI->first, SI->second, L, HasOneStride); |
Chris Lattner | 7305ae2 | 2005-10-09 06:20:55 +0000 | [diff] [blame] | 1080 | } |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 1081 | |
| 1082 | // Clean up after ourselves |
| 1083 | if (!DeadInsts.empty()) { |
| 1084 | DeleteTriviallyDeadInstructions(DeadInsts); |
| 1085 | |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 1086 | BasicBlock::iterator I = L->getHeader()->begin(); |
| 1087 | PHINode *PN; |
Chris Lattner | e9100c6 | 2005-08-02 02:44:31 +0000 | [diff] [blame] | 1088 | while ((PN = dyn_cast<PHINode>(I))) { |
Chris Lattner | 1060e09 | 2005-08-02 00:41:11 +0000 | [diff] [blame] | 1089 | ++I; // Preincrement iterator to avoid invalidating it when deleting PN. |
| 1090 | |
Chris Lattner | 87265ab | 2005-08-09 23:39:36 +0000 | [diff] [blame] | 1091 | // At this point, we know that we have killed one or more GEP |
| 1092 | // instructions. It is worth checking to see if the cann indvar is also |
| 1093 | // dead, so that we can remove it as well. The requirements for the cann |
| 1094 | // indvar to be considered dead are: |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 1095 | // 1. the cann indvar has one use |
| 1096 | // 2. the use is an add instruction |
| 1097 | // 3. the add has one use |
| 1098 | // 4. the add is used by the cann indvar |
| 1099 | // If all four cases above are true, then we can remove both the add and |
| 1100 | // the cann indvar. |
| 1101 | // FIXME: this needs to eliminate an induction variable even if it's being |
| 1102 | // compared against some value to decide loop termination. |
| 1103 | if (PN->hasOneUse()) { |
| 1104 | BinaryOperator *BO = dyn_cast<BinaryOperator>(*(PN->use_begin())); |
Chris Lattner | 7e608bb | 2005-08-02 02:52:02 +0000 | [diff] [blame] | 1105 | if (BO && BO->hasOneUse()) { |
| 1106 | if (PN == *(BO->use_begin())) { |
| 1107 | DeadInsts.insert(BO); |
| 1108 | // Break the cycle, then delete the PHI. |
| 1109 | PN->replaceAllUsesWith(UndefValue::get(PN->getType())); |
Chris Lattner | 52d83e6 | 2005-08-03 21:36:09 +0000 | [diff] [blame] | 1110 | SE->deleteInstructionFromRecords(PN); |
Chris Lattner | 7e608bb | 2005-08-02 02:52:02 +0000 | [diff] [blame] | 1111 | PN->eraseFromParent(); |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 1112 | } |
Chris Lattner | 7e608bb | 2005-08-02 02:52:02 +0000 | [diff] [blame] | 1113 | } |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 1114 | } |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 1115 | } |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 1116 | DeleteTriviallyDeadInstructions(DeadInsts); |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 1117 | } |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 1118 | |
Chris Lattner | 9a59fbb | 2005-08-05 01:30:11 +0000 | [diff] [blame] | 1119 | CastedPointers.clear(); |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 1120 | IVUsesByStride.clear(); |
Chris Lattner | 7305ae2 | 2005-10-09 06:20:55 +0000 | [diff] [blame] | 1121 | StrideOrder.clear(); |
Nate Begeman | 1699748 | 2005-07-30 00:15:07 +0000 | [diff] [blame] | 1122 | return; |
Nate Begeman | eaa1385 | 2004-10-18 21:08:22 +0000 | [diff] [blame] | 1123 | } |