summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChen Zheng <czhengsz@cn.ibm.com>2019-04-10 06:52:09 +0000
committerChen Zheng <czhengsz@cn.ibm.com>2019-04-10 06:52:09 +0000
commit5e13ff1da20bf02bbb256b2006dcbb42e06d300e (patch)
tree89db0bb6867870877d8f29cc79fce83dcdeca7a0 /llvm/lib
parent0c01607bbff3d58bc11c701b3657c7a02e036d7e (diff)
downloadbcm5719-llvm-5e13ff1da20bf02bbb256b2006dcbb42e06d300e.tar.gz
bcm5719-llvm-5e13ff1da20bf02bbb256b2006dcbb42e06d300e.zip
[InstCombine] Canonicalize (-X s/ Y) to -(X s/ Y).
Differential Revision: https://reviews.llvm.org/D60395 llvm-svn: 358050
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index cb8708446b2..e53eac2dd4e 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -1056,6 +1056,12 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
}
}
+ // -X / Y --> -(X / Y)
+ Value *Y;
+ if (match(&I, m_SDiv(m_OneUse(m_NSWSub(m_Zero(), m_Value(X))), m_Value(Y))))
+ return BinaryOperator::CreateNSWNeg(
+ Builder.CreateSDiv(X, Y, I.getName(), I.isExact()));
+
// If the sign bits of both operands are zero (i.e. we can prove they are
// unsigned inputs), turn this into a udiv.
APInt Mask(APInt::getSignMask(I.getType()->getScalarSizeInBits()));
OpenPOWER on IntegriCloud