diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2008-07-08 05:05:37 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2008-07-08 05:05:37 +0000 |
commit | 3c947045ef67a30d2a4400c820b3a9ab912ff92c (patch) | |
tree | c09bc1654b2edbb89324948106cc608af26f4711 /llvm/lib | |
parent | ba123cdb9cbac6c9c61cda4b299a559f732c579a (diff) | |
download | bcm5719-llvm-3c947045ef67a30d2a4400c820b3a9ab912ff92c.tar.gz bcm5719-llvm-3c947045ef67a30d2a4400c820b3a9ab912ff92c.zip |
Expand SCEVUDiv of power of 2 to a lshr instruction.
llvm-svn: 53217
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolutionExpander.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp index 593e27300d3..628129dc5f0 100644 --- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp @@ -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(); |