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