SimplifyIndVar.cpp 19 KB

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