[PM/AA] Clean up and homogenize comments throughout basic-aa.
[oota-llvm.git] / lib / Transforms / Utils / SimplifyIndVar.cpp
1 //===-- SimplifyIndVar.cpp - Induction variable simplification ------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements induction variable simplification. It does
11 // not define any actual pass or policy, but provides a single function to
12 // simplify a loop's induction variables based on ScalarEvolution.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "llvm/Transforms/Utils/SimplifyIndVar.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/Statistic.h"
20 #include "llvm/Analysis/LoopInfo.h"
21 #include "llvm/Analysis/LoopPass.h"
22 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
23 #include "llvm/IR/DataLayout.h"
24 #include "llvm/IR/Dominators.h"
25 #include "llvm/IR/IRBuilder.h"
26 #include "llvm/IR/Instructions.h"
27 #include "llvm/IR/IntrinsicInst.h"
28 #include "llvm/Support/CommandLine.h"
29 #include "llvm/Support/Debug.h"
30 #include "llvm/Support/raw_ostream.h"
31
32 using namespace llvm;
33
34 #define DEBUG_TYPE "indvars"
35
36 STATISTIC(NumElimIdentity, "Number of IV identities eliminated");
37 STATISTIC(NumElimOperand,  "Number of IV operands folded into a use");
38 STATISTIC(NumElimRem     , "Number of IV remainder operations eliminated");
39 STATISTIC(NumElimCmp     , "Number of IV comparisons eliminated");
40
41 namespace {
42   /// This is a utility for simplifying induction variables
43   /// based on ScalarEvolution. It is the primary instrument of the
44   /// IndvarSimplify pass, but it may also be directly invoked to cleanup after
45   /// other loop passes that preserve SCEV.
46   class SimplifyIndvar {
47     Loop             *L;
48     LoopInfo         *LI;
49     ScalarEvolution  *SE;
50
51     SmallVectorImpl<WeakVH> &DeadInsts;
52
53     bool Changed;
54
55   public:
56     SimplifyIndvar(Loop *Loop, ScalarEvolution *SE, LoopInfo *LI,
57                    SmallVectorImpl<WeakVH> &Dead)
58         : L(Loop), LI(LI), SE(SE), DeadInsts(Dead), Changed(false) {
59       assert(LI && "IV simplification requires LoopInfo");
60     }
61
62     bool hasChanged() const { return Changed; }
63
64     /// Iteratively perform simplification on a worklist of users of the
65     /// specified induction variable. This is the top-level driver that applies
66     /// all simplicitions to users of an IV.
67     void simplifyUsers(PHINode *CurrIV, IVVisitor *V = nullptr);
68
69     Value *foldIVUser(Instruction *UseInst, Instruction *IVOperand);
70
71     bool eliminateIVUser(Instruction *UseInst, Instruction *IVOperand);
72     void eliminateIVComparison(ICmpInst *ICmp, Value *IVOperand);
73     void eliminateIVRemainder(BinaryOperator *Rem, Value *IVOperand,
74                               bool IsSigned);
75     bool strengthenOverflowingOperation(BinaryOperator *OBO, Value *IVOperand);
76
77     Instruction *splitOverflowIntrinsic(Instruction *IVUser,
78                                         const DominatorTree *DT);
79   };
80 }
81
82 /// Fold an IV operand into its use.  This removes increments of an
83 /// aligned IV when used by a instruction that ignores the low bits.
84 ///
85 /// IVOperand is guaranteed SCEVable, but UseInst may not be.
86 ///
87 /// Return the operand of IVOperand for this induction variable if IVOperand can
88 /// be folded (in case more folding opportunities have been exposed).
89 /// Otherwise return null.
90 Value *SimplifyIndvar::foldIVUser(Instruction *UseInst, Instruction *IVOperand) {
91   Value *IVSrc = nullptr;
92   unsigned OperIdx = 0;
93   const SCEV *FoldedExpr = nullptr;
94   switch (UseInst->getOpcode()) {
95   default:
96     return nullptr;
97   case Instruction::UDiv:
98   case Instruction::LShr:
99     // We're only interested in the case where we know something about
100     // the numerator and have a constant denominator.
101     if (IVOperand != UseInst->getOperand(OperIdx) ||
102         !isa<ConstantInt>(UseInst->getOperand(1)))
103       return nullptr;
104
105     // Attempt to fold a binary operator with constant operand.
106     // e.g. ((I + 1) >> 2) => I >> 2
107     if (!isa<BinaryOperator>(IVOperand)
108         || !isa<ConstantInt>(IVOperand->getOperand(1)))
109       return nullptr;
110
111     IVSrc = IVOperand->getOperand(0);
112     // IVSrc must be the (SCEVable) IV, since the other operand is const.
113     assert(SE->isSCEVable(IVSrc->getType()) && "Expect SCEVable IV operand");
114
115     ConstantInt *D = cast<ConstantInt>(UseInst->getOperand(1));
116     if (UseInst->getOpcode() == Instruction::LShr) {
117       // Get a constant for the divisor. See createSCEV.
118       uint32_t BitWidth = cast<IntegerType>(UseInst->getType())->getBitWidth();
119       if (D->getValue().uge(BitWidth))
120         return nullptr;
121
122       D = ConstantInt::get(UseInst->getContext(),
123                            APInt::getOneBitSet(BitWidth, D->getZExtValue()));
124     }
125     FoldedExpr = SE->getUDivExpr(SE->getSCEV(IVSrc), SE->getSCEV(D));
126   }
127   // We have something that might fold it's operand. Compare SCEVs.
128   if (!SE->isSCEVable(UseInst->getType()))
129     return nullptr;
130
131   // Bypass the operand if SCEV can prove it has no effect.
132   if (SE->getSCEV(UseInst) != FoldedExpr)
133     return nullptr;
134
135   DEBUG(dbgs() << "INDVARS: Eliminated IV operand: " << *IVOperand
136         << " -> " << *UseInst << '\n');
137
138   UseInst->setOperand(OperIdx, IVSrc);
139   assert(SE->getSCEV(UseInst) == FoldedExpr && "bad SCEV with folded oper");
140
141   ++NumElimOperand;
142   Changed = true;
143   if (IVOperand->use_empty())
144     DeadInsts.emplace_back(IVOperand);
145   return IVSrc;
146 }
147
148 /// SimplifyIVUsers helper for eliminating useless
149 /// comparisons against an induction variable.
150 void SimplifyIndvar::eliminateIVComparison(ICmpInst *ICmp, Value *IVOperand) {
151   unsigned IVOperIdx = 0;
152   ICmpInst::Predicate Pred = ICmp->getPredicate();
153   if (IVOperand != ICmp->getOperand(0)) {
154     // Swapped
155     assert(IVOperand == ICmp->getOperand(1) && "Can't find IVOperand");
156     IVOperIdx = 1;
157     Pred = ICmpInst::getSwappedPredicate(Pred);
158   }
159
160   // Get the SCEVs for the ICmp operands.
161   const SCEV *S = SE->getSCEV(ICmp->getOperand(IVOperIdx));
162   const SCEV *X = SE->getSCEV(ICmp->getOperand(1 - IVOperIdx));
163
164   // Simplify unnecessary loops away.
165   const Loop *ICmpLoop = LI->getLoopFor(ICmp->getParent());
166   S = SE->getSCEVAtScope(S, ICmpLoop);
167   X = SE->getSCEVAtScope(X, ICmpLoop);
168
169   ICmpInst::Predicate InvariantPredicate;
170   const SCEV *InvariantLHS, *InvariantRHS;
171
172   const char *Verb = nullptr;
173
174   // If the condition is always true or always false, replace it with
175   // a constant value.
176   if (SE->isKnownPredicate(Pred, S, X)) {
177     ICmp->replaceAllUsesWith(ConstantInt::getTrue(ICmp->getContext()));
178     DeadInsts.emplace_back(ICmp);
179     Verb = "Eliminated";
180   } else if (SE->isKnownPredicate(ICmpInst::getInversePredicate(Pred), S, X)) {
181     ICmp->replaceAllUsesWith(ConstantInt::getFalse(ICmp->getContext()));
182     DeadInsts.emplace_back(ICmp);
183     Verb = "Eliminated";
184   } else if (isa<PHINode>(IVOperand) &&
185              SE->isLoopInvariantPredicate(Pred, S, X, ICmpLoop,
186                                           InvariantPredicate, InvariantLHS,
187                                           InvariantRHS)) {
188
189     // Rewrite the comparision to a loop invariant comparision if it can be done
190     // cheaply, where cheaply means "we don't need to emit any new
191     // instructions".
192
193     Value *NewLHS = nullptr, *NewRHS = nullptr;
194
195     if (S == InvariantLHS || X == InvariantLHS)
196       NewLHS =
197           ICmp->getOperand(S == InvariantLHS ? IVOperIdx : (1 - IVOperIdx));
198
199     if (S == InvariantRHS || X == InvariantRHS)
200       NewRHS =
201           ICmp->getOperand(S == InvariantRHS ? IVOperIdx : (1 - IVOperIdx));
202
203     for (Value *Incoming : cast<PHINode>(IVOperand)->incoming_values()) {
204       if (NewLHS && NewRHS)
205         break;
206
207       const SCEV *IncomingS = SE->getSCEV(Incoming);
208
209       if (!NewLHS && IncomingS == InvariantLHS)
210         NewLHS = Incoming;
211       if (!NewRHS && IncomingS == InvariantRHS)
212         NewRHS = Incoming;
213     }
214
215     if (!NewLHS || !NewRHS)
216       // We could not find an existing value to replace either LHS or RHS.
217       // Generating new instructions has subtler tradeoffs, so avoid doing that
218       // for now.
219       return;
220
221     Verb = "Simplified";
222     ICmp->setPredicate(InvariantPredicate);
223     ICmp->setOperand(0, NewLHS);
224     ICmp->setOperand(1, NewRHS);
225   } else
226     return;
227
228   DEBUG(dbgs() << "INDVARS: " << Verb << " comparison: " << *ICmp << '\n');
229   ++NumElimCmp;
230   Changed = true;
231 }
232
233 /// SimplifyIVUsers helper for eliminating useless
234 /// remainder operations operating on an induction variable.
235 void SimplifyIndvar::eliminateIVRemainder(BinaryOperator *Rem,
236                                       Value *IVOperand,
237                                       bool IsSigned) {
238   // We're only interested in the case where we know something about
239   // the numerator.
240   if (IVOperand != Rem->getOperand(0))
241     return;
242
243   // Get the SCEVs for the ICmp operands.
244   const SCEV *S = SE->getSCEV(Rem->getOperand(0));
245   const SCEV *X = SE->getSCEV(Rem->getOperand(1));
246
247   // Simplify unnecessary loops away.
248   const Loop *ICmpLoop = LI->getLoopFor(Rem->getParent());
249   S = SE->getSCEVAtScope(S, ICmpLoop);
250   X = SE->getSCEVAtScope(X, ICmpLoop);
251
252   // i % n  -->  i  if i is in [0,n).
253   if ((!IsSigned || SE->isKnownNonNegative(S)) &&
254       SE->isKnownPredicate(IsSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
255                            S, X))
256     Rem->replaceAllUsesWith(Rem->getOperand(0));
257   else {
258     // (i+1) % n  -->  (i+1)==n?0:(i+1)  if i is in [0,n).
259     const SCEV *LessOne =
260       SE->getMinusSCEV(S, SE->getConstant(S->getType(), 1));
261     if (IsSigned && !SE->isKnownNonNegative(LessOne))
262       return;
263
264     if (!SE->isKnownPredicate(IsSigned ?
265                               ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
266                               LessOne, X))
267       return;
268
269     ICmpInst *ICmp = new ICmpInst(Rem, ICmpInst::ICMP_EQ,
270                                   Rem->getOperand(0), Rem->getOperand(1));
271     SelectInst *Sel =
272       SelectInst::Create(ICmp,
273                          ConstantInt::get(Rem->getType(), 0),
274                          Rem->getOperand(0), "tmp", Rem);
275     Rem->replaceAllUsesWith(Sel);
276   }
277
278   DEBUG(dbgs() << "INDVARS: Simplified rem: " << *Rem << '\n');
279   ++NumElimRem;
280   Changed = true;
281   DeadInsts.emplace_back(Rem);
282 }
283
284 /// Eliminate an operation that consumes a simple IV and has
285 /// no observable side-effect given the range of IV values.
286 /// IVOperand is guaranteed SCEVable, but UseInst may not be.
287 bool SimplifyIndvar::eliminateIVUser(Instruction *UseInst,
288                                      Instruction *IVOperand) {
289   if (ICmpInst *ICmp = dyn_cast<ICmpInst>(UseInst)) {
290     eliminateIVComparison(ICmp, IVOperand);
291     return true;
292   }
293   if (BinaryOperator *Rem = dyn_cast<BinaryOperator>(UseInst)) {
294     bool IsSigned = Rem->getOpcode() == Instruction::SRem;
295     if (IsSigned || Rem->getOpcode() == Instruction::URem) {
296       eliminateIVRemainder(Rem, IVOperand, IsSigned);
297       return true;
298     }
299   }
300
301   // Eliminate any operation that SCEV can prove is an identity function.
302   if (!SE->isSCEVable(UseInst->getType()) ||
303       (UseInst->getType() != IVOperand->getType()) ||
304       (SE->getSCEV(UseInst) != SE->getSCEV(IVOperand)))
305     return false;
306
307   DEBUG(dbgs() << "INDVARS: Eliminated identity: " << *UseInst << '\n');
308
309   UseInst->replaceAllUsesWith(IVOperand);
310   ++NumElimIdentity;
311   Changed = true;
312   DeadInsts.emplace_back(UseInst);
313   return true;
314 }
315
316 /// Annotate BO with nsw / nuw if it provably does not signed-overflow /
317 /// unsigned-overflow.  Returns true if anything changed, false otherwise.
318 bool SimplifyIndvar::strengthenOverflowingOperation(BinaryOperator *BO,
319                                                     Value *IVOperand) {
320
321   // Fastpath: we don't have any work to do if `BO` is `nuw` and `nsw`.
322   if (BO->hasNoUnsignedWrap() && BO->hasNoSignedWrap())
323     return false;
324
325   const SCEV *(ScalarEvolution::*GetExprForBO)(const SCEV *, const SCEV *,
326                                                SCEV::NoWrapFlags);
327
328   switch (BO->getOpcode()) {
329   default:
330     return false;
331
332   case Instruction::Add:
333     GetExprForBO = &ScalarEvolution::getAddExpr;
334     break;
335
336   case Instruction::Sub:
337     GetExprForBO = &ScalarEvolution::getMinusSCEV;
338     break;
339
340   case Instruction::Mul:
341     GetExprForBO = &ScalarEvolution::getMulExpr;
342     break;
343   }
344
345   unsigned BitWidth = cast<IntegerType>(BO->getType())->getBitWidth();
346   Type *WideTy = IntegerType::get(BO->getContext(), BitWidth * 2);
347   const SCEV *LHS = SE->getSCEV(BO->getOperand(0));
348   const SCEV *RHS = SE->getSCEV(BO->getOperand(1));
349
350   bool Changed = false;
351
352   if (!BO->hasNoUnsignedWrap()) {
353     const SCEV *ExtendAfterOp = SE->getZeroExtendExpr(SE->getSCEV(BO), WideTy);
354     const SCEV *OpAfterExtend = (SE->*GetExprForBO)(
355       SE->getZeroExtendExpr(LHS, WideTy), SE->getZeroExtendExpr(RHS, WideTy),
356       SCEV::FlagAnyWrap);
357     if (ExtendAfterOp == OpAfterExtend) {
358       BO->setHasNoUnsignedWrap();
359       SE->forgetValue(BO);
360       Changed = true;
361     }
362   }
363
364   if (!BO->hasNoSignedWrap()) {
365     const SCEV *ExtendAfterOp = SE->getSignExtendExpr(SE->getSCEV(BO), WideTy);
366     const SCEV *OpAfterExtend = (SE->*GetExprForBO)(
367       SE->getSignExtendExpr(LHS, WideTy), SE->getSignExtendExpr(RHS, WideTy),
368       SCEV::FlagAnyWrap);
369     if (ExtendAfterOp == OpAfterExtend) {
370       BO->setHasNoSignedWrap();
371       SE->forgetValue(BO);
372       Changed = true;
373     }
374   }
375
376   return Changed;
377 }
378
379 /// \brief Split sadd.with.overflow into add + sadd.with.overflow to allow
380 /// analysis and optimization.
381 ///
382 /// \return A new value representing the non-overflowing add if possible,
383 /// otherwise return the original value.
384 Instruction *SimplifyIndvar::splitOverflowIntrinsic(Instruction *IVUser,
385                                                     const DominatorTree *DT) {
386   IntrinsicInst *II = dyn_cast<IntrinsicInst>(IVUser);
387   if (!II || II->getIntrinsicID() != Intrinsic::sadd_with_overflow)
388     return IVUser;
389
390   // Find a branch guarded by the overflow check.
391   BranchInst *Branch = nullptr;
392   Instruction *AddVal = nullptr;
393   for (User *U : II->users()) {
394     if (ExtractValueInst *ExtractInst = dyn_cast<ExtractValueInst>(U)) {
395       if (ExtractInst->getNumIndices() != 1)
396         continue;
397       if (ExtractInst->getIndices()[0] == 0)
398         AddVal = ExtractInst;
399       else if (ExtractInst->getIndices()[0] == 1 && ExtractInst->hasOneUse())
400         Branch = dyn_cast<BranchInst>(ExtractInst->user_back());
401     }
402   }
403   if (!AddVal || !Branch)
404     return IVUser;
405
406   BasicBlock *ContinueBB = Branch->getSuccessor(1);
407   if (std::next(pred_begin(ContinueBB)) != pred_end(ContinueBB))
408     return IVUser;
409
410   // Check if all users of the add are provably NSW.
411   bool AllNSW = true;
412   for (Use &U : AddVal->uses()) {
413     if (Instruction *UseInst = dyn_cast<Instruction>(U.getUser())) {
414       BasicBlock *UseBB = UseInst->getParent();
415       if (PHINode *PHI = dyn_cast<PHINode>(UseInst))
416         UseBB = PHI->getIncomingBlock(U);
417       if (!DT->dominates(ContinueBB, UseBB)) {
418         AllNSW = false;
419         break;
420       }
421     }
422   }
423   if (!AllNSW)
424     return IVUser;
425
426   // Go for it...
427   IRBuilder<> Builder(IVUser);
428   Instruction *AddInst = dyn_cast<Instruction>(
429     Builder.CreateNSWAdd(II->getOperand(0), II->getOperand(1)));
430
431   // The caller expects the new add to have the same form as the intrinsic. The
432   // IV operand position must be the same.
433   assert((AddInst->getOpcode() == Instruction::Add &&
434           AddInst->getOperand(0) == II->getOperand(0)) &&
435          "Bad add instruction created from overflow intrinsic.");
436
437   AddVal->replaceAllUsesWith(AddInst);
438   DeadInsts.emplace_back(AddVal);
439   return AddInst;
440 }
441
442 /// Add all uses of Def to the current IV's worklist.
443 static void pushIVUsers(
444   Instruction *Def,
445   SmallPtrSet<Instruction*,16> &Simplified,
446   SmallVectorImpl< std::pair<Instruction*,Instruction*> > &SimpleIVUsers) {
447
448   for (User *U : Def->users()) {
449     Instruction *UI = cast<Instruction>(U);
450
451     // Avoid infinite or exponential worklist processing.
452     // Also ensure unique worklist users.
453     // If Def is a LoopPhi, it may not be in the Simplified set, so check for
454     // self edges first.
455     if (UI != Def && Simplified.insert(UI).second)
456       SimpleIVUsers.push_back(std::make_pair(UI, Def));
457   }
458 }
459
460 /// Return true if this instruction generates a simple SCEV
461 /// expression in terms of that IV.
462 ///
463 /// This is similar to IVUsers' isInteresting() but processes each instruction
464 /// non-recursively when the operand is already known to be a simpleIVUser.
465 ///
466 static bool isSimpleIVUser(Instruction *I, const Loop *L, ScalarEvolution *SE) {
467   if (!SE->isSCEVable(I->getType()))
468     return false;
469
470   // Get the symbolic expression for this instruction.
471   const SCEV *S = SE->getSCEV(I);
472
473   // Only consider affine recurrences.
474   const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(S);
475   if (AR && AR->getLoop() == L)
476     return true;
477
478   return false;
479 }
480
481 /// Iteratively perform simplification on a worklist of users
482 /// of the specified induction variable. Each successive simplification may push
483 /// more users which may themselves be candidates for simplification.
484 ///
485 /// This algorithm does not require IVUsers analysis. Instead, it simplifies
486 /// instructions in-place during analysis. Rather than rewriting induction
487 /// variables bottom-up from their users, it transforms a chain of IVUsers
488 /// top-down, updating the IR only when it encouters a clear optimization
489 /// opportunitiy.
490 ///
491 /// Once DisableIVRewrite is default, LSR will be the only client of IVUsers.
492 ///
493 void SimplifyIndvar::simplifyUsers(PHINode *CurrIV, IVVisitor *V) {
494   if (!SE->isSCEVable(CurrIV->getType()))
495     return;
496
497   // Instructions processed by SimplifyIndvar for CurrIV.
498   SmallPtrSet<Instruction*,16> Simplified;
499
500   // Use-def pairs if IV users waiting to be processed for CurrIV.
501   SmallVector<std::pair<Instruction*, Instruction*>, 8> SimpleIVUsers;
502
503   // Push users of the current LoopPhi. In rare cases, pushIVUsers may be
504   // called multiple times for the same LoopPhi. This is the proper thing to
505   // do for loop header phis that use each other.
506   pushIVUsers(CurrIV, Simplified, SimpleIVUsers);
507
508   while (!SimpleIVUsers.empty()) {
509     std::pair<Instruction*, Instruction*> UseOper =
510       SimpleIVUsers.pop_back_val();
511     Instruction *UseInst = UseOper.first;
512
513     // Bypass back edges to avoid extra work.
514     if (UseInst == CurrIV) continue;
515
516     if (V && V->shouldSplitOverflowInstrinsics()) {
517       UseInst = splitOverflowIntrinsic(UseInst, V->getDomTree());
518       if (!UseInst)
519         continue;
520     }
521
522     Instruction *IVOperand = UseOper.second;
523     for (unsigned N = 0; IVOperand; ++N) {
524       assert(N <= Simplified.size() && "runaway iteration");
525
526       Value *NewOper = foldIVUser(UseOper.first, IVOperand);
527       if (!NewOper)
528         break; // done folding
529       IVOperand = dyn_cast<Instruction>(NewOper);
530     }
531     if (!IVOperand)
532       continue;
533
534     if (eliminateIVUser(UseOper.first, IVOperand)) {
535       pushIVUsers(IVOperand, Simplified, SimpleIVUsers);
536       continue;
537     }
538
539     if (BinaryOperator *BO = dyn_cast<BinaryOperator>(UseOper.first)) {
540       if (isa<OverflowingBinaryOperator>(BO) &&
541           strengthenOverflowingOperation(BO, IVOperand)) {
542         // re-queue uses of the now modified binary operator and fall
543         // through to the checks that remain.
544         pushIVUsers(IVOperand, Simplified, SimpleIVUsers);
545       }
546     }
547
548     CastInst *Cast = dyn_cast<CastInst>(UseOper.first);
549     if (V && Cast) {
550       V->visitCast(Cast);
551       continue;
552     }
553     if (isSimpleIVUser(UseOper.first, L, SE)) {
554       pushIVUsers(UseOper.first, Simplified, SimpleIVUsers);
555     }
556   }
557 }
558
559 namespace llvm {
560
561 void IVVisitor::anchor() { }
562
563 /// Simplify instructions that use this induction variable
564 /// by using ScalarEvolution to analyze the IV's recurrence.
565 bool simplifyUsersOfIV(PHINode *CurrIV, ScalarEvolution *SE, LPPassManager *LPM,
566                        SmallVectorImpl<WeakVH> &Dead, IVVisitor *V)
567 {
568   LoopInfo *LI = &LPM->getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
569   SimplifyIndvar SIV(LI->getLoopFor(CurrIV->getParent()), SE, LI, Dead);
570   SIV.simplifyUsers(CurrIV, V);
571   return SIV.hasChanged();
572 }
573
574 /// Simplify users of induction variables within this
575 /// loop. This does not actually change or add IVs.
576 bool simplifyLoopIVs(Loop *L, ScalarEvolution *SE, LPPassManager *LPM,
577                      SmallVectorImpl<WeakVH> &Dead) {
578   bool Changed = false;
579   for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ++I) {
580     Changed |= simplifyUsersOfIV(cast<PHINode>(I), SE, LPM, Dead);
581   }
582   return Changed;
583 }
584
585 } // namespace llvm