/// 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<Constant>(LHS))
+ if (Constant *CRHS = dyn_cast<Constant>(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();
}
// 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) {
return expand(V);
}
+
+Value *SCEVExpander::expand(SCEV *S) {
+ // Check to see if we already expanded this.
+ std::map<SCEVHandle, Value*>::iterator I = InsertedExpressions.find(S);
+ if (I != InsertedExpressions.end())
+ return I->second;
+
+ Value *V = visit(S);
+ InsertedExpressions[S] = V;
+ return V;
+}
+