blob: ebd2bf055bc0a2a0ddcc1fe1dfd40869538cc861 [file] [log] [blame]
Nate Begemaneaa13852004-10-18 21:08:22 +00001//===- LoopStrengthReduce.cpp - Strength Reduce GEPs in Loops -------------===//
Misha Brukmanfd939082005-04-21 23:48:37 +00002//
Nate Begemaneaa13852004-10-18 21:08:22 +00003// 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 Brukmanfd939082005-04-21 23:48:37 +00007//
Nate Begemaneaa13852004-10-18 21:08:22 +00008//===----------------------------------------------------------------------===//
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 Begemaneaa13852004-10-18 21:08:22 +000016//===----------------------------------------------------------------------===//
17
Chris Lattnerbe3e5212005-08-03 23:30:08 +000018#define DEBUG_TYPE "loop-reduce"
Nate Begemaneaa13852004-10-18 21:08:22 +000019#include "llvm/Transforms/Scalar.h"
20#include "llvm/Constants.h"
21#include "llvm/Instructions.h"
22#include "llvm/Type.h"
Jeff Cohen2f3c9b72005-03-04 04:04:26 +000023#include "llvm/DerivedTypes.h"
Nate Begemaneaa13852004-10-18 21:08:22 +000024#include "llvm/Analysis/Dominators.h"
25#include "llvm/Analysis/LoopInfo.h"
Nate Begeman16997482005-07-30 00:15:07 +000026#include "llvm/Analysis/ScalarEvolutionExpander.h"
Nate Begemaneaa13852004-10-18 21:08:22 +000027#include "llvm/Support/CFG.h"
Nate Begeman16997482005-07-30 00:15:07 +000028#include "llvm/Support/GetElementPtrTypeIterator.h"
Chris Lattnere0391be2005-08-12 22:06:11 +000029#include "llvm/Transforms/Utils/BasicBlockUtils.h"
Nate Begemaneaa13852004-10-18 21:08:22 +000030#include "llvm/Transforms/Utils/Local.h"
Jeff Cohen2f3c9b72005-03-04 04:04:26 +000031#include "llvm/Target/TargetData.h"
Nate Begemaneaa13852004-10-18 21:08:22 +000032#include "llvm/ADT/Statistic.h"
Nate Begeman16997482005-07-30 00:15:07 +000033#include "llvm/Support/Debug.h"
Jeff Cohencfb1d422005-07-30 18:22:27 +000034#include <algorithm>
Nate Begemaneaa13852004-10-18 21:08:22 +000035#include <set>
36using namespace llvm;
37
38namespace {
39 Statistic<> NumReduced ("loop-reduce", "Number of GEPs strength reduced");
Chris Lattner26d91f12005-08-04 22:34:05 +000040 Statistic<> NumInserted("loop-reduce", "Number of PHIs inserted");
Chris Lattner50fad702005-08-10 00:45:21 +000041 Statistic<> NumVariable("loop-reduce","Number of PHIs with variable strides");
Nate Begemaneaa13852004-10-18 21:08:22 +000042
Chris Lattnerec3fb632005-08-03 22:21:05 +000043 /// 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 Lattner010de252005-08-08 05:28:22 +000051
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 Lattnerc6bae652005-09-12 06:04:47 +000055 // instruction for a loop or uses dominated by the loop.
Chris Lattner010de252005-08-08 05:28:22 +000056 bool isUseOfPostIncrementedValue;
Chris Lattnerec3fb632005-08-03 22:21:05 +000057
58 IVStrideUse(const SCEVHandle &Offs, Instruction *U, Value *O)
Chris Lattner010de252005-08-08 05:28:22 +000059 : Offset(Offs), User(U), OperandValToReplace(O),
60 isUseOfPostIncrementedValue(false) {}
Chris Lattnerec3fb632005-08-03 22:21:05 +000061 };
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 Begeman16997482005-07-30 00:15:07 +000068 /// Users - Keep track of all of the users of this stride as well as the
Chris Lattnerec3fb632005-08-03 22:21:05 +000069 /// 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 Begeman16997482005-07-30 00:15:07 +000074 }
75 };
76
77
Nate Begemaneaa13852004-10-18 21:08:22 +000078 class LoopStrengthReduce : public FunctionPass {
79 LoopInfo *LI;
Chris Lattner88cac3d2006-01-11 05:10:20 +000080 ETForest *EF;
Nate Begeman16997482005-07-30 00:15:07 +000081 ScalarEvolution *SE;
82 const TargetData *TD;
83 const Type *UIntPtrTy;
Nate Begemaneaa13852004-10-18 21:08:22 +000084 bool Changed;
Chris Lattner7e608bb2005-08-02 02:52:02 +000085
86 /// MaxTargetAMSize - This is the maximum power-of-two scale value that the
87 /// target can handle for free with its addressing modes.
Jeff Cohen2f3c9b72005-03-04 04:04:26 +000088 unsigned MaxTargetAMSize;
Nate Begeman16997482005-07-30 00:15:07 +000089
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 Lattner50fad702005-08-10 00:45:21 +000092 std::map<SCEVHandle, IVUsersOfOneStride> IVUsesByStride;
Nate Begeman16997482005-07-30 00:15:07 +000093
Chris Lattner7305ae22005-10-09 06:20:55 +000094 /// 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 Lattner49f72e62005-08-04 01:19:13 +000099 /// 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 Begeman16997482005-07-30 00:15:07 +0000103
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 Begemaneaa13852004-10-18 21:08:22 +0000107 public:
Jeff Cohen2f3c9b72005-03-04 04:04:26 +0000108 LoopStrengthReduce(unsigned MTAMS = 1)
109 : MaxTargetAMSize(MTAMS) {
110 }
111
Nate Begemaneaa13852004-10-18 21:08:22 +0000112 virtual bool runOnFunction(Function &) {
113 LI = &getAnalysis<LoopInfo>();
Chris Lattner88cac3d2006-01-11 05:10:20 +0000114 EF = &getAnalysis<ETForest>();
Nate Begeman16997482005-07-30 00:15:07 +0000115 SE = &getAnalysis<ScalarEvolution>();
116 TD = &getAnalysis<TargetData>();
117 UIntPtrTy = TD->getIntPtrType();
Nate Begemaneaa13852004-10-18 21:08:22 +0000118 Changed = false;
119
120 for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I)
121 runOnLoop(*I);
Chris Lattner49f72e62005-08-04 01:19:13 +0000122
Nate Begemaneaa13852004-10-18 21:08:22 +0000123 return Changed;
124 }
125
126 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
Chris Lattneraa96ae72005-08-17 06:35:16 +0000127 // 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 Lattner88cac3d2006-01-11 05:10:20 +0000132 AU.addPreserved<ETForest>();
Chris Lattneraa96ae72005-08-17 06:35:16 +0000133 AU.addPreserved<ImmediateDominators>();
134 AU.addPreserved<DominanceFrontier>();
135 AU.addPreserved<DominatorTree>();
136
Jeff Cohenf465db62005-02-27 19:37:07 +0000137 AU.addRequiredID(LoopSimplifyID);
Nate Begemaneaa13852004-10-18 21:08:22 +0000138 AU.addRequired<LoopInfo>();
Chris Lattner88cac3d2006-01-11 05:10:20 +0000139 AU.addRequired<ETForest>();
Jeff Cohen2f3c9b72005-03-04 04:04:26 +0000140 AU.addRequired<TargetData>();
Nate Begeman16997482005-07-30 00:15:07 +0000141 AU.addRequired<ScalarEvolution>();
Nate Begemaneaa13852004-10-18 21:08:22 +0000142 }
Chris Lattner49f72e62005-08-04 01:19:13 +0000143
144 /// getCastedVersionOf - Return the specified value casted to uintptr_t.
145 ///
146 Value *getCastedVersionOf(Value *V);
147private:
Nate Begemaneaa13852004-10-18 21:08:22 +0000148 void runOnLoop(Loop *L);
Chris Lattner3416e5f2005-08-04 17:40:30 +0000149 bool AddUsersIfInteresting(Instruction *I, Loop *L,
150 std::set<Instruction*> &Processed);
151 SCEVHandle GetExpressionSCEV(Instruction *E, Loop *L);
152
Chris Lattner010de252005-08-08 05:28:22 +0000153 void OptimizeIndvars(Loop *L);
Nate Begeman16997482005-07-30 00:15:07 +0000154
Chris Lattner50fad702005-08-10 00:45:21 +0000155 void StrengthReduceStridedIVUsers(const SCEVHandle &Stride,
156 IVUsersOfOneStride &Uses,
Chris Lattnerec3fb632005-08-03 22:21:05 +0000157 Loop *L, bool isOnlyStride);
Nate Begemaneaa13852004-10-18 21:08:22 +0000158 void DeleteTriviallyDeadInstructions(std::set<Instruction*> &Insts);
159 };
Misha Brukmanfd939082005-04-21 23:48:37 +0000160 RegisterOpt<LoopStrengthReduce> X("loop-reduce",
Chris Lattnerfe158302005-09-27 21:10:32 +0000161 "Loop Strength Reduction");
Nate Begemaneaa13852004-10-18 21:08:22 +0000162}
163
Jeff Cohen2f3c9b72005-03-04 04:04:26 +0000164FunctionPass *llvm::createLoopStrengthReducePass(unsigned MaxTargetAMSize) {
165 return new LoopStrengthReduce(MaxTargetAMSize);
Nate Begemaneaa13852004-10-18 21:08:22 +0000166}
167
Chris Lattner49f72e62005-08-04 01:19:13 +0000168/// getCastedVersionOf - Return the specified value casted to uintptr_t.
169///
170Value *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 Lattner7db543f2005-08-04 19:08:16 +0000194
195 New = new CastInst(V, UIntPtrTy, V->getName(), InsertPt);
196 DeadInsts.insert(cast<Instruction>(New));
197 return New;
Chris Lattner49f72e62005-08-04 01:19:13 +0000198}
199
200
Nate Begemaneaa13852004-10-18 21:08:22 +0000201/// 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.
204void LoopStrengthReduce::
205DeleteTriviallyDeadInstructions(std::set<Instruction*> &Insts) {
206 while (!Insts.empty()) {
207 Instruction *I = *Insts.begin();
208 Insts.erase(Insts.begin());
209 if (isInstructionTriviallyDead(I)) {
Jeff Cohen0456e4a2005-03-01 03:46:11 +0000210 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 Lattner52d83e62005-08-03 21:36:09 +0000213 SE->deleteInstructionFromRecords(I);
214 I->eraseFromParent();
Nate Begemaneaa13852004-10-18 21:08:22 +0000215 Changed = true;
216 }
217 }
218}
219
Jeff Cohenf465db62005-02-27 19:37:07 +0000220
Chris Lattner3416e5f2005-08-04 17:40:30 +0000221/// GetExpressionSCEV - Compute and return the SCEV for the specified
222/// instruction.
223SCEVHandle LoopStrengthReduce::GetExpressionSCEV(Instruction *Exp, Loop *L) {
Chris Lattner87265ab2005-08-09 23:39:36 +0000224 // 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 Lattner3416e5f2005-08-04 17:40:30 +0000228 GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Exp);
Chris Lattner87265ab2005-08-09 23:39:36 +0000229 if (!GEP || SE->hasSCEV(GEP))
Chris Lattner3416e5f2005-08-04 17:40:30 +0000230 return SE->getSCEV(Exp);
231
Nate Begeman16997482005-07-30 00:15:07 +0000232 // 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 Lattner3416e5f2005-08-04 17:40:30 +0000238 SCEVHandle GEPVal = SCEVUnknown::get(getCastedVersionOf(GEP->getOperand(0)));
Nate Begeman16997482005-07-30 00:15:07 +0000239
240 gep_type_iterator GTI = gep_type_begin(GEP);
Chris Lattner3416e5f2005-08-04 17:40:30 +0000241
242 for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i, ++GTI) {
Nate Begeman16997482005-07-30 00:15:07 +0000243 // 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 Lattner3416e5f2005-08-04 17:40:30 +0000250 GEPVal = SCEVAddExpr::get(GEPVal,
251 SCEVUnknown::getIntegerSCEV(Offset, UIntPtrTy));
Nate Begeman16997482005-07-30 00:15:07 +0000252 } else {
Chris Lattner7db543f2005-08-04 19:08:16 +0000253 Value *OpVal = getCastedVersionOf(GEP->getOperand(i));
254 SCEVHandle Idx = SE->getSCEV(OpVal);
255
Chris Lattner3416e5f2005-08-04 17:40:30 +0000256 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 Begeman16997482005-07-30 00:15:07 +0000262 }
263 }
264
Chris Lattner87265ab2005-08-09 23:39:36 +0000265 SE->setSCEV(GEP, GEPVal);
Chris Lattner3416e5f2005-08-04 17:40:30 +0000266 return GEPVal;
Nate Begeman16997482005-07-30 00:15:07 +0000267}
268
Chris Lattner7db543f2005-08-04 19:08:16 +0000269/// 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.
273static bool getSCEVStartAndStride(const SCEVHandle &SH, Loop *L,
Chris Lattner50fad702005-08-10 00:45:21 +0000274 SCEVHandle &Start, SCEVHandle &Stride) {
Chris Lattner7db543f2005-08-04 19:08:16 +0000275 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 Lattner7db543f2005-08-04 19:08:16 +0000305 if (!isa<SCEVConstant>(AddRec->getOperand(1)))
Chris Lattner50fad702005-08-10 00:45:21 +0000306 DEBUG(std::cerr << "[" << L->getHeader()->getName()
307 << "] Variable stride: " << *AddRec << "\n");
Chris Lattner7db543f2005-08-04 19:08:16 +0000308
Chris Lattner50fad702005-08-10 00:45:21 +0000309 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 Lattner7db543f2005-08-04 19:08:16 +0000314 "Constants should be canonicalized to unsigned!");
Chris Lattner50fad702005-08-10 00:45:21 +0000315
Chris Lattner7db543f2005-08-04 19:08:16 +0000316 return true;
317}
318
Chris Lattner0ae33eb2005-10-03 01:04:44 +0000319/// 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).
327static bool IVUseShouldUsePostIncValue(Instruction *User, Instruction *IV,
Chris Lattner88cac3d2006-01-11 05:10:20 +0000328 Loop *L, ETForest *EF, Pass *P) {
Chris Lattner0ae33eb2005-10-03 01:04:44 +0000329 // If the user is in the loop, use the preinc value.
330 if (L->contains(User->getParent())) return false;
331
Chris Lattner5e8ca662005-10-03 02:50:05 +0000332 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 Lattner88cac3d2006-01-11 05:10:20 +0000336 if (EF->dominates(LatchBlock, User->getParent()))
Chris Lattner5e8ca662005-10-03 02:50:05 +0000337 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 Lattner88cac3d2006-01-11 05:10:20 +0000353 if (!EF->dominates(LatchBlock, PN->getIncomingBlock(i)))
Chris Lattner5e8ca662005-10-03 02:50:05 +0000354 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 Lattner0ae33eb2005-10-03 01:04:44 +0000367}
368
369
370
Nate Begeman16997482005-07-30 00:15:07 +0000371/// 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 Lattner3416e5f2005-08-04 17:40:30 +0000374bool LoopStrengthReduce::AddUsersIfInteresting(Instruction *I, Loop *L,
375 std::set<Instruction*> &Processed) {
Chris Lattner63ad7962005-10-21 05:45:41 +0000376 if (!I->getType()->isInteger() && !isa<PointerType>(I->getType()))
377 return false; // Void and FP expressions cannot be reduced.
Chris Lattner3416e5f2005-08-04 17:40:30 +0000378 if (!Processed.insert(I).second)
379 return true; // Instruction already handled.
380
Chris Lattner7db543f2005-08-04 19:08:16 +0000381 // Get the symbolic expression for this instruction.
Chris Lattner3416e5f2005-08-04 17:40:30 +0000382 SCEVHandle ISE = GetExpressionSCEV(I, L);
Chris Lattner7db543f2005-08-04 19:08:16 +0000383 if (isa<SCEVCouldNotCompute>(ISE)) return false;
Chris Lattner3416e5f2005-08-04 17:40:30 +0000384
Chris Lattner7db543f2005-08-04 19:08:16 +0000385 // Get the start and stride for this expression.
386 SCEVHandle Start = SCEVUnknown::getIntegerSCEV(0, ISE->getType());
Chris Lattner50fad702005-08-10 00:45:21 +0000387 SCEVHandle Stride = Start;
Chris Lattner7db543f2005-08-04 19:08:16 +0000388 if (!getSCEVStartAndStride(ISE, L, Start, Stride))
389 return false; // Non-reducible symbolic expression, bail out.
390
Nate Begeman16997482005-07-30 00:15:07 +0000391 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 Lattner396b2ba2005-09-13 02:09:55 +0000395 if (isa<PHINode>(User) && Processed.count(User))
Nate Begeman16997482005-07-30 00:15:07 +0000396 continue;
397
398 // If this is an instruction defined in a nested loop, or outside this loop,
Chris Lattnerf9186592005-08-04 00:14:11 +0000399 // don't recurse into it.
Chris Lattner7db543f2005-08-04 19:08:16 +0000400 bool AddUserToIVUsers = false;
Chris Lattnerf9186592005-08-04 00:14:11 +0000401 if (LI->getLoopFor(User->getParent()) != L) {
Chris Lattner396b2ba2005-09-13 02:09:55 +0000402 DEBUG(std::cerr << "FOUND USER in other loop: " << *User
Chris Lattnerf9186592005-08-04 00:14:11 +0000403 << " OF SCEV: " << *ISE << "\n");
Chris Lattner7db543f2005-08-04 19:08:16 +0000404 AddUserToIVUsers = true;
Chris Lattner3416e5f2005-08-04 17:40:30 +0000405 } else if (!AddUsersIfInteresting(User, L, Processed)) {
Chris Lattnera4479ad2005-08-04 00:40:47 +0000406 DEBUG(std::cerr << "FOUND USER: " << *User
407 << " OF SCEV: " << *ISE << "\n");
Chris Lattner7db543f2005-08-04 19:08:16 +0000408 AddUserToIVUsers = true;
409 }
Nate Begeman16997482005-07-30 00:15:07 +0000410
Chris Lattner7db543f2005-08-04 19:08:16 +0000411 if (AddUserToIVUsers) {
Chris Lattner7305ae22005-10-09 06:20:55 +0000412 IVUsersOfOneStride &StrideUses = IVUsesByStride[Stride];
413 if (StrideUses.Users.empty()) // First occurance of this stride?
414 StrideOrder.push_back(Stride);
415
Chris Lattnera4479ad2005-08-04 00:40:47 +0000416 // Okay, we found a user that we cannot reduce. Analyze the instruction
Chris Lattnerc6bae652005-09-12 06:04:47 +0000417 // 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 Lattner88cac3d2006-01-11 05:10:20 +0000419 if (IVUseShouldUsePostIncValue(User, I, L, EF, this)) {
Chris Lattnerc6bae652005-09-12 06:04:47 +0000420 // 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 Lattner7305ae22005-10-09 06:20:55 +0000423 StrideUses.addUser(NewStart, User, I);
424 StrideUses.Users.back().isUseOfPostIncrementedValue = true;
Chris Lattner5e8ca662005-10-03 02:50:05 +0000425 DEBUG(std::cerr << " USING POSTINC SCEV, START=" << *NewStart<< "\n");
Chris Lattner0ae33eb2005-10-03 01:04:44 +0000426 } else {
Chris Lattner7305ae22005-10-09 06:20:55 +0000427 StrideUses.addUser(Start, User, I);
Chris Lattnerc6bae652005-09-12 06:04:47 +0000428 }
Nate Begeman16997482005-07-30 00:15:07 +0000429 }
430 }
431 return true;
432}
433
434namespace {
435 /// BasedUser - For a particular base value, keep information about how we've
436 /// partitioned the expression so far.
437 struct BasedUser {
Chris Lattnera553b0c2005-08-08 22:56:21 +0000438 /// 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 Begeman16997482005-07-30 00:15:07 +0000444 /// Inst - The instruction using the induction variable.
445 Instruction *Inst;
446
Chris Lattnerec3fb632005-08-03 22:21:05 +0000447 /// OperandValToReplace - The operand value of Inst to replace with the
448 /// EmittedBase.
449 Value *OperandValToReplace;
Nate Begeman16997482005-07-30 00:15:07 +0000450
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 Lattner010de252005-08-08 05:28:22 +0000460 // 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 Lattnerc6bae652005-09-12 06:04:47 +0000463 // instruction for a loop and uses outside the loop that are dominated by
464 // the loop.
Chris Lattner010de252005-08-08 05:28:22 +0000465 bool isUseOfPostIncrementedValue;
Chris Lattnera553b0c2005-08-08 22:56:21 +0000466
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 Begeman16997482005-07-30 00:15:07 +0000472
Chris Lattner2114b272005-08-04 20:03:32 +0000473 // 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 Lattner1bbae0c2005-08-09 00:18:09 +0000476 void RewriteInstructionToUseNewBase(const SCEVHandle &NewBase,
Chris Lattnerc60fb082005-08-12 22:22:17 +0000477 SCEVExpander &Rewriter, Loop *L,
478 Pass *P);
Nate Begeman16997482005-07-30 00:15:07 +0000479 void dump() const;
480 };
481}
482
483void BasedUser::dump() const {
Chris Lattnera553b0c2005-08-08 22:56:21 +0000484 std::cerr << " Base=" << *Base;
Nate Begeman16997482005-07-30 00:15:07 +0000485 std::cerr << " Imm=" << *Imm;
486 if (EmittedBase)
487 std::cerr << " EB=" << *EmittedBase;
488
489 std::cerr << " Inst: " << *Inst;
490}
491
Chris Lattner2114b272005-08-04 20:03:32 +0000492// 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 Lattner1bbae0c2005-08-09 00:18:09 +0000495void BasedUser::RewriteInstructionToUseNewBase(const SCEVHandle &NewBase,
Chris Lattnere0391be2005-08-12 22:06:11 +0000496 SCEVExpander &Rewriter,
Chris Lattnerc60fb082005-08-12 22:22:17 +0000497 Loop *L, Pass *P) {
Chris Lattner2114b272005-08-04 20:03:32 +0000498 if (!isa<PHINode>(Inst)) {
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000499 SCEVHandle NewValSCEV = SCEVAddExpr::get(NewBase, Imm);
Chris Lattner2114b272005-08-04 20:03:32 +0000500 Value *NewVal = Rewriter.expandCodeFor(NewValSCEV, Inst,
501 OperandValToReplace->getType());
Chris Lattner2114b272005-08-04 20:03:32 +0000502 // 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 Lattnerc41e3452005-08-10 00:35:32 +0000509 // 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 Lattner2114b272005-08-04 20:03:32 +0000514 PHINode *PN = cast<PHINode>(Inst);
515 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
516 if (PN->getIncomingValue(i) == OperandValToReplace) {
Chris Lattnere0391be2005-08-12 22:06:11 +0000517 // If this is a critical edge, split the edge so that we do not insert the
Chris Lattner396b2ba2005-09-13 02:09:55 +0000518 // 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 Lattner37edbf02005-10-03 00:31:52 +0000521 BasicBlock *PHIPred = PN->getIncomingBlock(i);
522 if (e != 1 && PHIPred->getTerminator()->getNumSuccessors() > 1 &&
523 (PN->getParent() != L->getHeader() || !L->contains(PHIPred))) {
Chris Lattner37edbf02005-10-03 00:31:52 +0000524
Chris Lattneraa96ae72005-08-17 06:35:16 +0000525 // First step, split the critical edge.
Chris Lattner37edbf02005-10-03 00:31:52 +0000526 SplitCriticalEdge(PHIPred, PN->getParent(), P);
Chris Lattnerc60fb082005-08-12 22:22:17 +0000527
Chris Lattneraa96ae72005-08-17 06:35:16 +0000528 // 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 Lattner37edbf02005-10-03 00:31:52 +0000532 if (L->contains(PHIPred) && !L->contains(PN->getParent())) {
Chris Lattneraa96ae72005-08-17 06:35:16 +0000533 BasicBlock *NewBB = PN->getIncomingBlock(i);
534 NewBB->moveBefore(PN->getParent());
Chris Lattnere0391be2005-08-12 22:06:11 +0000535 }
536 }
Chris Lattner2114b272005-08-04 20:03:32 +0000537
Chris Lattnerc41e3452005-08-10 00:35:32 +0000538 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 Lattner2114b272005-08-04 20:03:32 +0000542
Chris Lattnerc41e3452005-08-10 00:35:32 +0000543 SCEVHandle NewValSCEV = SCEVAddExpr::get(NewBase, Imm);
544 Code = Rewriter.expandCodeFor(NewValSCEV, InsertPt,
545 OperandValToReplace->getType());
546 }
Chris Lattner2114b272005-08-04 20:03:32 +0000547
548 // Replace the use of the operand Value with the new Phi we just created.
Chris Lattnerc41e3452005-08-10 00:35:32 +0000549 PN->setIncomingValue(i, Code);
Chris Lattner2114b272005-08-04 20:03:32 +0000550 Rewriter.clear();
551 }
552 }
553 DEBUG(std::cerr << " CHANGED: IMM =" << *Imm << " Inst = " << *Inst);
554}
555
556
Nate Begeman16997482005-07-30 00:15:07 +0000557/// isTargetConstant - Return true if the following can be referenced by the
558/// immediate field of a target instruction.
559static bool isTargetConstant(const SCEVHandle &V) {
Jeff Cohend29b6aa2005-07-30 18:33:25 +0000560
Nate Begeman16997482005-07-30 00:15:07 +0000561 // FIXME: Look at the target to decide if &GV is a legal constant immediate.
Chris Lattner3821e472005-08-08 06:25:50 +0000562 if (SCEVConstant *SC = dyn_cast<SCEVConstant>(V)) {
563 // PPC allows a sign-extended 16-bit immediate field.
Chris Lattnere08dc622005-12-05 18:23:57 +0000564 int64_t V = SC->getValue()->getSExtValue();
565 if (V > -(1 << 16) && V < (1 << 16)-1)
566 return true;
Chris Lattner3821e472005-08-08 06:25:50 +0000567 return false;
568 }
Jeff Cohend29b6aa2005-07-30 18:33:25 +0000569
Nate Begeman16997482005-07-30 00:15:07 +0000570 return false; // ENABLE this for x86
Jeff Cohend29b6aa2005-07-30 18:33:25 +0000571
Nate Begeman16997482005-07-30 00:15:07 +0000572 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 Lattner44b807e2005-08-08 22:32:34 +0000581/// MoveLoopVariantsToImediateField - Move any subexpressions from Val that are
582/// loop varying to the Imm operand.
583static 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 Lattner26d91f12005-08-04 22:34:05 +0000620/// MoveImmediateValues - Look at Val, and pull out any additions of constants
Nate Begeman16997482005-07-30 00:15:07 +0000621/// that can fit into the immediate field of instructions in the target.
Chris Lattner26d91f12005-08-04 22:34:05 +0000622/// Accumulate these immediate values into the Imm value.
623static void MoveImmediateValues(SCEVHandle &Val, SCEVHandle &Imm,
624 bool isAddress, Loop *L) {
Chris Lattner7a658392005-08-03 23:44:42 +0000625 if (SCEVAddExpr *SAE = dyn_cast<SCEVAddExpr>(Val)) {
Chris Lattner26d91f12005-08-04 22:34:05 +0000626 std::vector<SCEVHandle> NewOps;
627 NewOps.reserve(SAE->getNumOperands());
628
629 for (unsigned i = 0; i != SAE->getNumOperands(); ++i)
Chris Lattner7db543f2005-08-04 19:08:16 +0000630 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 Lattner26d91f12005-08-04 22:34:05 +0000636 } else {
637 NewOps.push_back(SAE->getOperand(i));
Nate Begeman16997482005-07-30 00:15:07 +0000638 }
Chris Lattner26d91f12005-08-04 22:34:05 +0000639
640 if (NewOps.empty())
641 Val = SCEVUnknown::getIntegerSCEV(0, Val->getType());
642 else
643 Val = SCEVAddExpr::get(NewOps);
644 return;
Chris Lattner7a658392005-08-03 23:44:42 +0000645 } else if (SCEVAddRecExpr *SARE = dyn_cast<SCEVAddRecExpr>(Val)) {
646 // Try to pull immediates out of the start value of nested addrec's.
Chris Lattner26d91f12005-08-04 22:34:05 +0000647 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 Begeman16997482005-07-30 00:15:07 +0000656 }
657
Chris Lattner26d91f12005-08-04 22:34:05 +0000658 // 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 Lattner7a2ca562005-08-04 19:26:19 +0000665 }
Chris Lattner26d91f12005-08-04 22:34:05 +0000666
667 // Otherwise, no immediates to move.
Nate Begeman16997482005-07-30 00:15:07 +0000668}
669
Chris Lattner934520a2005-08-13 07:27:18 +0000670
671/// IncrementAddExprUses - Decompose the specified expression into its added
672/// subexpressions, and increment SubExpressionUseCounts for each of these
673/// decomposed parts.
674static 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 Lattner1bbae0c2005-08-09 00:18:09 +0000700/// 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.
704static SCEVHandle
705RemoveCommonExpressionsFromUseBases(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 Lattnerd6155e92005-10-11 18:41:04 +0000720 // UniqueSubExprs - Keep track of all of the subexpressions we see in the
721 // order we see them.
722 std::vector<SCEVHandle> UniqueSubExprs;
723
Chris Lattner934520a2005-08-13 07:27:18 +0000724 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 Lattnerd6155e92005-10-11 18:41:04 +0000734 if (++SubExpressionUseCounts[SubExprs[j]] == 1)
735 UniqueSubExprs.push_back(SubExprs[j]);
Chris Lattner934520a2005-08-13 07:27:18 +0000736 SubExprs.clear();
737 }
738
Chris Lattnerd6155e92005-10-11 18:41:04 +0000739 // 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 Lattner1bbae0c2005-08-09 00:18:09 +0000745 if (I->second == NumUses) { // Found CSE!
746 Result = SCEVAddExpr::get(Result, I->first);
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000747 } else {
748 // Remove non-cse's from SubExpressionUseCounts.
Chris Lattnerd6155e92005-10-11 18:41:04 +0000749 SubExpressionUseCounts.erase(I);
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000750 }
Chris Lattnerd6155e92005-10-11 18:41:04 +0000751 }
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000752
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 Lattner934520a2005-08-13 07:27:18 +0000757 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 Lattner1bbae0c2005-08-09 00:18:09 +0000770 Uses[i].Base = Zero;
Chris Lattner934520a2005-08-13 07:27:18 +0000771 else
772 Uses[i].Base = SCEVAddExpr::get(SubExprs);
Chris Lattner27e51422005-08-13 07:42:01 +0000773 SubExprs.clear();
Chris Lattner934520a2005-08-13 07:27:18 +0000774 }
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000775
776 return Result;
777}
778
779
Nate Begeman16997482005-07-30 00:15:07 +0000780/// 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 Lattner50fad702005-08-10 00:45:21 +0000783void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride,
Chris Lattnerec3fb632005-08-03 22:21:05 +0000784 IVUsersOfOneStride &Uses,
785 Loop *L,
Nate Begeman16997482005-07-30 00:15:07 +0000786 bool isOnlyStride) {
787 // Transform our list of users and offsets to a bit more complex table. In
Chris Lattnera553b0c2005-08-08 22:56:21 +0000788 // 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 Begeman16997482005-07-30 00:15:07 +0000793 UsersToProcess.reserve(Uses.Users.size());
Chris Lattnera553b0c2005-08-08 22:56:21 +0000794 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 Lattner26d91f12005-08-04 22:34:05 +0000803 "Base value is not loop invariant!");
Nate Begeman16997482005-07-30 00:15:07 +0000804 }
Chris Lattner44b807e2005-08-08 22:32:34 +0000805
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000806 // 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 Lattner44b807e2005-08-08 22:32:34 +0000815 // 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 Lattner1bbae0c2005-08-09 00:18:09 +0000817 // fields of the BasedUsers. We do this so that it increases the commonality
818 // of the remaining uses.
Chris Lattner44b807e2005-08-08 22:32:34 +0000819 for (unsigned i = 0, e = UsersToProcess.size(); i != e; ++i) {
Chris Lattner80b32b32005-08-16 00:38:11 +0000820 // 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 Lattner8385e512005-08-17 21:22:41 +0000824 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 Lattner80b32b32005-08-16 00:38:11 +0000828 } 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 Lattner44b807e2005-08-08 22:32:34 +0000840 }
841
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000842 // 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 Lattner44b807e2005-08-08 22:32:34 +0000849
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000850 BasicBlock *Preheader = L->getLoopPreheader();
851 Instruction *PreInsertPt = Preheader->getTerminator();
852 Instruction *PhiInsertBefore = L->getHeader()->begin();
Chris Lattner44b807e2005-08-08 22:32:34 +0000853
Chris Lattner12b50412005-09-12 17:11:27 +0000854 BasicBlock *LatchBlock = L->getLoopLatch();
Chris Lattnerbe3e5212005-08-03 23:30:08 +0000855
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000856 // 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 Lattner50fad702005-08-10 00:45:21 +0000861 // Insert the stride into the preheader.
862 Value *StrideV = PreheaderRewriter.expandCodeFor(Stride, PreInsertPt,
863 ReplacedTy);
864 if (!isa<ConstantInt>(StrideV)) ++NumVariable;
865
866
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000867 // 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 Lattner50fad702005-08-10 00:45:21 +0000876 SCEVUnknown::get(StrideV));
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000877
878 Value *IncV = Rewriter.expandCodeFor(IncExp, LatchBlock->getTerminator(),
879 ReplacedTy);
880 IncV->setName(NewPHI->getName()+".inc");
881 NewPHI->addIncoming(IncV, LatchBlock);
882
Chris Lattner2351aba2005-08-03 22:51:21 +0000883 // Sort by the base value, so that all IVs with identical bases are next to
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000884 // each other.
Nate Begeman16997482005-07-30 00:15:07 +0000885 while (!UsersToProcess.empty()) {
Chris Lattner7b445c52005-10-11 18:30:57 +0000886 SCEVHandle Base = UsersToProcess.back().Base;
Chris Lattnerbe3e5212005-08-03 23:30:08 +0000887
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000888 DEBUG(std::cerr << " INSERTING code for BASE = " << *Base << ":\n");
Chris Lattnerbe3e5212005-08-03 23:30:08 +0000889
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000890 // Emit the code for Base into the preheader.
Chris Lattner5272f3c2005-08-08 05:47:49 +0000891 Value *BaseV = PreheaderRewriter.expandCodeFor(Base, PreInsertPt,
892 ReplacedTy);
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000893
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 Lattner7259df32005-09-10 01:18:45 +0000899 if (!C->isNullValue() && !isTargetConstant(Base)) {
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000900 // We want this constant emitted into the preheader!
901 BaseV = new CastInst(BaseV, BaseV->getType(), "preheaderinsert",
902 PreInsertPt);
903 }
904
Nate Begeman16997482005-07-30 00:15:07 +0000905 // Emit the code to add the immediate offset to the Phi value, just before
Chris Lattner2351aba2005-08-03 22:51:21 +0000906 // the instructions that we identified as using this stride and base.
Chris Lattner7b445c52005-10-11 18:30:57 +0000907 unsigned ScanPos = 0;
908 do {
909 BasedUser &User = UsersToProcess.back();
Jeff Cohend29b6aa2005-07-30 18:33:25 +0000910
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000911 // 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 Lattnerc6bae652005-09-12 06:04:47 +0000916
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 Lattner1bbae0c2005-08-09 00:18:09 +0000921 }
922 SCEVHandle RewriteExpr = SCEVUnknown::get(RewriteOp);
923
Chris Lattner2351aba2005-08-03 22:51:21 +0000924 // 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 Lattner1bbae0c2005-08-09 00:18:09 +0000927
Chris Lattner2114b272005-08-04 20:03:32 +0000928 // Now that we know what we need to do, insert code before User for the
929 // immediate and any loop-variant expressions.
Chris Lattner1bbae0c2005-08-09 00:18:09 +0000930 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 Lattnerc60fb082005-08-12 22:22:17 +0000934 User.RewriteInstructionToUseNewBase(RewriteExpr, Rewriter, L, this);
Jeff Cohend29b6aa2005-07-30 18:33:25 +0000935
Chris Lattner2351aba2005-08-03 22:51:21 +0000936 // 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 Lattner2114b272005-08-04 20:03:32 +0000938 DeadInsts.insert(cast<Instruction>(User.OperandValToReplace));
Nate Begeman16997482005-07-30 00:15:07 +0000939
Chris Lattner7b445c52005-10-11 18:30:57 +0000940 UsersToProcess.pop_back();
Chris Lattner2351aba2005-08-03 22:51:21 +0000941 ++NumReduced;
Chris Lattner7b445c52005-10-11 18:30:57 +0000942
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 Begeman16997482005-07-30 00:15:07 +0000953 // 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 Begeman16997482005-07-30 00:15:07 +0000958}
959
Chris Lattner010de252005-08-08 05:28:22 +0000960// 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.
963void 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 Lattner50fad702005-08-10 00:45:21 +0000985 const SCEVHandle *CondStride = 0;
Chris Lattner010de252005-08-08 05:28:22 +0000986
Chris Lattnerb4dd1b82005-10-11 18:17:57 +0000987 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 Lattner010de252005-08-08 05:28:22 +0000995 if (UI->User == Cond) {
996 CondUse = &*UI;
Chris Lattnerb4dd1b82005-10-11 18:17:57 +0000997 CondStride = &SI->first;
Chris Lattner010de252005-08-08 05:28:22 +0000998 // 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 Lattnerb4dd1b82005-10-11 18:17:57 +00001003 }
Chris Lattner010de252005-08-08 05:28:22 +00001004 if (!CondUse) return; // setcc doesn't use the IV.
1005
1006 // setcc stride is complex, don't mess with users.
Chris Lattner50fad702005-08-10 00:45:21 +00001007 // FIXME: Evaluate whether this is a good idea or not.
1008 if (!isa<SCEVConstant>(*CondStride)) return;
Chris Lattner010de252005-08-08 05:28:22 +00001009
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 Lattner50fad702005-08-10 00:45:21 +00001023 IVUsesByStride[*CondStride].addUser(CondUse->Offset, Cond,
Chris Lattner010de252005-08-08 05:28:22 +00001024 CondUse->OperandValToReplace);
Chris Lattner50fad702005-08-10 00:45:21 +00001025 CondUse = &IVUsesByStride[*CondStride].Users.back();
Chris Lattner010de252005-08-08 05:28:22 +00001026 }
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 Lattner50fad702005-08-10 00:45:21 +00001032 CondUse->Offset = SCEV::getMinusSCEV(CondUse->Offset, *CondStride);
Chris Lattner010de252005-08-08 05:28:22 +00001033 CondUse->isUseOfPostIncrementedValue = true;
1034}
Nate Begeman16997482005-07-30 00:15:07 +00001035
Nate Begemaneaa13852004-10-18 21:08:22 +00001036void 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 Begeman16997482005-07-30 00:15:07 +00001041 // 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 Lattner3416e5f2005-08-04 17:40:30 +00001044 std::set<Instruction*> Processed; // Don't reprocess instructions.
Nate Begeman16997482005-07-30 00:15:07 +00001045 for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ++I)
Chris Lattner3416e5f2005-08-04 17:40:30 +00001046 AddUsersIfInteresting(I, L, Processed);
Nate Begemaneaa13852004-10-18 21:08:22 +00001047
Nate Begeman16997482005-07-30 00:15:07 +00001048 // If we have nothing to do, return.
Chris Lattner010de252005-08-08 05:28:22 +00001049 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 Brukmanfd939082005-04-21 23:48:37 +00001057
Nate Begeman16997482005-07-30 00:15:07 +00001058 // 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 Lattner7305ae22005-10-09 06:20:55 +00001069
Chris Lattner1bbae0c2005-08-09 00:18:09 +00001070 // Note: this processes each stride/type pair individually. All users passed
Chris Lattner7305ae22005-10-09 06:20:55 +00001071 // 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 Begeman16997482005-07-30 00:15:07 +00001079 StrengthReduceStridedIVUsers(SI->first, SI->second, L, HasOneStride);
Chris Lattner7305ae22005-10-09 06:20:55 +00001080 }
Nate Begemaneaa13852004-10-18 21:08:22 +00001081
1082 // Clean up after ourselves
1083 if (!DeadInsts.empty()) {
1084 DeleteTriviallyDeadInstructions(DeadInsts);
1085
Nate Begeman16997482005-07-30 00:15:07 +00001086 BasicBlock::iterator I = L->getHeader()->begin();
1087 PHINode *PN;
Chris Lattnere9100c62005-08-02 02:44:31 +00001088 while ((PN = dyn_cast<PHINode>(I))) {
Chris Lattner1060e092005-08-02 00:41:11 +00001089 ++I; // Preincrement iterator to avoid invalidating it when deleting PN.
1090
Chris Lattner87265ab2005-08-09 23:39:36 +00001091 // 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 Begeman16997482005-07-30 00:15:07 +00001095 // 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 Lattner7e608bb2005-08-02 02:52:02 +00001105 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 Lattner52d83e62005-08-03 21:36:09 +00001110 SE->deleteInstructionFromRecords(PN);
Chris Lattner7e608bb2005-08-02 02:52:02 +00001111 PN->eraseFromParent();
Nate Begemaneaa13852004-10-18 21:08:22 +00001112 }
Chris Lattner7e608bb2005-08-02 02:52:02 +00001113 }
Nate Begeman16997482005-07-30 00:15:07 +00001114 }
Nate Begemaneaa13852004-10-18 21:08:22 +00001115 }
Nate Begeman16997482005-07-30 00:15:07 +00001116 DeleteTriviallyDeadInstructions(DeadInsts);
Nate Begemaneaa13852004-10-18 21:08:22 +00001117 }
Nate Begeman16997482005-07-30 00:15:07 +00001118
Chris Lattner9a59fbb2005-08-05 01:30:11 +00001119 CastedPointers.clear();
Nate Begeman16997482005-07-30 00:15:07 +00001120 IVUsesByStride.clear();
Chris Lattner7305ae22005-10-09 06:20:55 +00001121 StrideOrder.clear();
Nate Begeman16997482005-07-30 00:15:07 +00001122 return;
Nate Begemaneaa13852004-10-18 21:08:22 +00001123}