Expand SCEVUDiv of power of 2 to a lshr instruction.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53217 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nick Lewycky 2008-07-08 05:05:37 +00:00
parent 77c8f7674d
commit 6177fd4fce
2 changed files with 15 additions and 5 deletions

View File

@ -102,11 +102,7 @@ namespace llvm {
Value *visitMulExpr(SCEVMulExpr *S);
Value *visitUDivExpr(SCEVUDivExpr *S) {
Value *LHS = expand(S->getLHS());
Value *RHS = expand(S->getRHS());
return InsertBinop(Instruction::UDiv, LHS, RHS, InsertPt);
}
Value *visitUDivExpr(SCEVUDivExpr *S);
Value *visitAddRecExpr(SCEVAddRecExpr *S);

View File

@ -129,6 +129,20 @@ 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::visitAddRecExpr(SCEVAddRecExpr *S) {
const Type *Ty = S->getType();
const Loop *L = S->getLoop();