diff options
author | Chris Lattner <sabre@nondot.org> | 2004-04-22 14:59:40 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-04-22 14:59:40 +0000 |
commit | fcb81f5f4cbac61851b7dec403961cf88e614aa1 (patch) | |
tree | 16e5913d188429f4d6f3fc6300e511c66aae53a3 /lib/Transforms/Scalar | |
parent | e1beb8f59d076536b0022496d663344a792a8cab (diff) | |
download | external_llvm-fcb81f5f4cbac61851b7dec403961cf88e614aa1.zip external_llvm-fcb81f5f4cbac61851b7dec403961cf88e614aa1.tar.gz external_llvm-fcb81f5f4cbac61851b7dec403961cf88e614aa1.tar.bz2 |
Fix an extremely serious thinko I made in revision 1.60 of this file.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13106 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar')
-rw-r--r-- | lib/Transforms/Scalar/IndVarSimplify.cpp | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index dbe3900..6ffe80a 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -390,8 +390,10 @@ void IndVarSimplify::runOnLoop(Loop *L) { // Compute the type of the largest recurrence expression. // const Type *LargestType = IndVars[0].first->getType(); + bool DifferingSizes = false; for (unsigned i = 1, e = IndVars.size(); i != e; ++i) { const Type *Ty = IndVars[i].first->getType(); + DifferingSizes |= Ty->getPrimitiveSize() != LargestType->getPrimitiveSize(); if (Ty->getPrimitiveSize() > LargestType->getPrimitiveSize()) LargestType = Ty; } @@ -418,26 +420,34 @@ void IndVarSimplify::runOnLoop(Loop *L) { // If there were induction variables of other sizes, cast the primary // induction variable to the right size for them, avoiding the need for the // code evaluation methods to insert induction variables of different sizes. + if (DifferingSizes) { + bool InsertedSizes[17] = { false }; + InsertedSizes[LargestType->getPrimitiveSize()] = true; + for (unsigned i = 0, e = IndVars.size(); i != e; ++i) + if (!InsertedSizes[IndVars[i].first->getType()->getPrimitiveSize()]) { + PHINode *PN = IndVars[i].first; + InsertedSizes[PN->getType()->getPrimitiveSize()] = true; + Instruction *New = new CastInst(IndVar, + PN->getType()->getUnsignedVersion(), + "indvar", InsertPt); + Rewriter.addInsertedValue(New, SE->getSCEV(New)); + } + } + + // If there were induction variables of other sizes, cast the primary + // induction variable to the right size for them, avoiding the need for the + // code evaluation methods to insert induction variables of different sizes. std::map<unsigned, Value*> InsertedSizes; - InsertedSizes[LargestType->getPrimitiveSize()] = IndVar; while (!IndVars.empty()) { PHINode *PN = IndVars.back().first; - - const Type *Ty = PN->getType()->getUnsignedVersion(); - Value *&IV = InsertedSizes[Ty->getPrimitiveSize()]; - if (IV == 0) { - // Insert a new cast instruction, which will hold this recurrence. - std::string Name = PN->getName(); - PN->setName(""); - IV = new CastInst(IndVar, Ty, Name, InsertPt); - } - - Value *V = IV; - if (PN->getType() != Ty) - V = new CastInst(V, PN->getType(), V->getName(), InsertPt); + Value *NewVal = Rewriter.ExpandCodeFor(IndVars.back().second, InsertPt, + PN->getType()); + std::string Name = PN->getName(); + PN->setName(""); + NewVal->setName(Name); // Replace the old PHI Node with the inserted computation. - PN->replaceAllUsesWith(V); + PN->replaceAllUsesWith(NewVal); DeadInsts.insert(PN); IndVars.pop_back(); ++NumRemoved; @@ -469,6 +479,5 @@ void IndVarSimplify::runOnLoop(Loop *L) { } } - DeleteTriviallyDeadInstructions(DeadInsts); } |