summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2016-06-27 17:25:57 +0000
committerSanjay Patel <spatel@rotateright.com>2016-06-27 17:25:57 +0000
commitc6ada53be5ba03b8cb764abb4a7a0777ddcf60ad (patch)
treee86b1d42b2b0db0b28ed6d40026f008e9d7c74fd /llvm/lib
parentb0f59cb5a8ad1037dd5e1c202d745a6c162f647a (diff)
downloadbcm5719-llvm-c6ada53be5ba03b8cb764abb4a7a0777ddcf60ad.tar.gz
bcm5719-llvm-c6ada53be5ba03b8cb764abb4a7a0777ddcf60ad.zip
[InstCombine] use m_APInt for div --> ashr fold
The APInt matcher works with splat vectors, so we get this fold for vectors too. llvm-svn: 273897
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index 5fb337db165..d7bd80261ab 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -1143,14 +1143,12 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
if (match(Op1, m_AllOnes()))
return BinaryOperator::CreateNeg(Op0);
- if (ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
- // sdiv X, C --> ashr exact X, log2(C)
- if (I.isExact() && RHS->getValue().isNonNegative() &&
- RHS->getValue().isPowerOf2()) {
- Value *ShAmt = llvm::ConstantInt::get(RHS->getType(),
- RHS->getValue().exactLogBase2());
- return BinaryOperator::CreateExactAShr(Op0, ShAmt, I.getName());
- }
+ // sdiv exact X, C --> ashr exact X, log2(C)
+ const APInt *Op1C;
+ if (match(Op1, m_APInt(Op1C)) && I.isExact() && Op1C->isNonNegative() &&
+ Op1C->isPowerOf2()) {
+ Value *ShAmt = ConstantInt::get(Op1->getType(), Op1C->exactLogBase2());
+ return BinaryOperator::CreateExactAShr(Op0, ShAmt, I.getName());
}
if (Constant *RHS = dyn_cast<Constant>(Op1)) {
OpenPOWER on IntegriCloud