+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);
+}
+