Today the front-ends (llvm-gcc and clang) generate multiple llvm.dbg.compile_units...
[oota-llvm.git] / lib / Analysis / ScalarEvolutionExpander.cpp
index 07850f77a14ebe8b62e4dc540869c8ad08f52909..211f013c25c49f8577521a010eafc27e795ae21a 100644 (file)
@@ -129,6 +129,29 @@ Value *SCEVExpander::visitMulExpr(SCEVMulExpr *S) {
   return V;
 }
 
+Value *SCEVExpander::visitUDivExpr(SCEVUDivExpr *S) {
+  Value *LHS = expand(S->getLHS());
+  if (SCEVConstant *SC = dyn_cast<SCEVConstant>(S->getRHS())) {
+    const APInt &RHS = SC->getValue()->getValue();
+    if (RHS.isPowerOf2())
+      return InsertBinop(Instruction::LShr, LHS,
+                         ConstantInt::get(S->getType(), RHS.logBase2()),
+                         InsertPt);
+  }
+
+  Value *RHS = expand(S->getRHS());
+  return InsertBinop(Instruction::UDiv, LHS, RHS, InsertPt);
+}
+
+Value *SCEVExpander::visitSDivExpr(SCEVSDivExpr *S) {
+  // Do not fold sdiv into ashr, unless you know that LHS is positive. On
+  // negative values, it rounds the wrong way.
+
+  Value *LHS = expand(S->getLHS());
+  Value *RHS = expand(S->getRHS());
+  return InsertBinop(Instruction::SDiv, LHS, RHS, InsertPt);
+}
+
 Value *SCEVExpander::visitAddRecExpr(SCEVAddRecExpr *S) {
   const Type *Ty = S->getType();
   const Loop *L = S->getLoop();
@@ -147,7 +170,7 @@ Value *SCEVExpander::visitAddRecExpr(SCEVAddRecExpr *S) {
   }
 
   // {0,+,1} --> Insert a canonical induction variable into the loop!
-  if (S->getNumOperands() == 2 &&
+  if (S->isAffine() &&
       S->getOperand(1) == SE.getIntegerSCEV(1, Ty)) {
     // Create and insert the PHI node for the induction variable in the
     // specified loop.
@@ -178,7 +201,7 @@ Value *SCEVExpander::visitAddRecExpr(SCEVAddRecExpr *S) {
   Value *I = getOrInsertCanonicalInductionVariable(L, Ty);
 
   // If this is a simple linear addrec, emit it now as a special case.
-  if (S->getNumOperands() == 2) {   // {0,+,F} --> i*F
+  if (S->isAffine()) {   // {0,+,F} --> i*F
     Value *F = expand(S->getOperand(1));
     
     // IF the step is by one, just return the inserted IV.
@@ -228,17 +251,17 @@ Value *SCEVExpander::visitAddRecExpr(SCEVAddRecExpr *S) {
 
 Value *SCEVExpander::visitTruncateExpr(SCEVTruncateExpr *S) {
   Value *V = expand(S->getOperand());
-  return CastInst::createTruncOrBitCast(V, S->getType(), "tmp.", InsertPt);
+  return CastInst::CreateTruncOrBitCast(V, S->getType(), "tmp.", InsertPt);
 }
 
 Value *SCEVExpander::visitZeroExtendExpr(SCEVZeroExtendExpr *S) {
   Value *V = expand(S->getOperand());
-  return CastInst::createZExtOrBitCast(V, S->getType(), "tmp.", InsertPt);
+  return CastInst::CreateZExtOrBitCast(V, S->getType(), "tmp.", InsertPt);
 }
 
 Value *SCEVExpander::visitSignExtendExpr(SCEVSignExtendExpr *S) {
   Value *V = expand(S->getOperand());
-  return CastInst::createSExtOrBitCast(V, S->getType(), "tmp.", InsertPt);
+  return CastInst::CreateSExtOrBitCast(V, S->getType(), "tmp.", InsertPt);
 }
 
 Value *SCEVExpander::visitSMaxExpr(SCEVSMaxExpr *S) {