X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAnalysis%2FScalarEvolutionExpander.cpp;h=fc52fb70ff7baa90e450ce1a555aea80c60c322b;hb=68099d58cbad1fc6de980b2b01b6f221b560d5d5;hp=c8c683cb3f62e7fe68c64791d962af75b045ac9b;hpb=d19534add90a2a894af61523b830887097bb780b;p=oota-llvm.git diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp index c8c683cb3f6..fc52fb70ff7 100644 --- a/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/lib/Analysis/ScalarEvolutionExpander.cpp @@ -72,6 +72,11 @@ Value *SCEVExpander::InsertCastOfTo(Instruction::CastOps opcode, Value *V, /// of work to avoid inserting an obviously redundant operation. Value *SCEVExpander::InsertBinop(Instruction::BinaryOps Opcode, Value *LHS, Value *RHS, Instruction *&InsertPt) { + // Fold a binop with constant operands. + if (Constant *CLHS = dyn_cast(LHS)) + if (Constant *CRHS = dyn_cast(RHS)) + return ConstantExpr::get(Opcode, CLHS, CRHS); + // Do a quick scan to see if we have this binop nearby. If so, reuse it. unsigned ScanLimit = 6; for (BasicBlock::iterator IP = InsertPt, E = InsertPt->getParent()->begin(); @@ -89,7 +94,7 @@ Value *SCEVExpander::InsertBinop(Instruction::BinaryOps Opcode, Value *LHS, } // If we don't have - return BinaryOperator::create(Opcode, LHS, RHS, "tmp.", InsertPt); + return BinaryOperator::create(Opcode, LHS, RHS, "tmp", InsertPt); } Value *SCEVExpander::visitMulExpr(SCEVMulExpr *S) { @@ -202,3 +207,15 @@ Value *SCEVExpander::visitAddRecExpr(SCEVAddRecExpr *S) { return expand(V); } + +Value *SCEVExpander::expand(SCEV *S) { + // Check to see if we already expanded this. + std::map::iterator I = InsertedExpressions.find(S); + if (I != InsertedExpressions.end()) + return I->second; + + Value *V = visit(S); + InsertedExpressions[S] = V; + return V; +} +