summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-08-11 20:47:47 +0000
committerDan Gohman <gohman@apple.com>2009-08-11 20:47:47 +0000
commitdbae4db67a01a007646b0f9da5db408cc846906c (patch)
treec5dedf8b691e8a6489b2873c59311093dae6ea30 /llvm/lib/Transforms/Scalar/InstructionCombining.cpp
parent9f94459d24d82504f0962dfe366a5b39576c4809 (diff)
downloadbcm5719-llvm-dbae4db67a01a007646b0f9da5db408cc846906c.tar.gz
bcm5719-llvm-dbae4db67a01a007646b0f9da5db408cc846906c.zip
Optimize exact sdiv by a constant power of 2 to ashr.
llvm-svn: 78714
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index b9b4ccb6cfb..798e3d24e9f 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -3064,6 +3064,15 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
// sdiv X, -1 == -X
if (RHS->isAllOnesValue())
return BinaryOperator::CreateNeg(*Context, Op0);
+
+ // sdiv X, C --> ashr X, log2(C)
+ if (cast<SDivOperator>(&I)->isExact() &&
+ RHS->getValue().isNonNegative() &&
+ RHS->getValue().isPowerOf2()) {
+ Value *ShAmt = llvm::ConstantInt::get(RHS->getType(),
+ RHS->getValue().exactLogBase2());
+ return BinaryOperator::CreateAShr(Op0, ShAmt, I.getName());
+ }
}
// If the sign bits of both operands are zero (i.e. we can prove they are
OpenPOWER on IntegriCloud