summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine
diff options
context:
space:
mode:
authorChen Zheng <czhengsz@cn.ibm.com>2019-04-09 16:34:31 +0000
committerChen Zheng <czhengsz@cn.ibm.com>2019-04-09 16:34:31 +0000
commit1383a9168948aabfd827220c9445ce0ce5765800 (patch)
tree68a8036eec4a2c0bec8b402cf3b7a1107e856dbe /llvm/lib/Transforms/InstCombine
parent366f4d45c0079e0d9b0c973aeaf459840629c0b1 (diff)
downloadbcm5719-llvm-1383a9168948aabfd827220c9445ce0ce5765800.tar.gz
bcm5719-llvm-1383a9168948aabfd827220c9445ce0ce5765800.zip
[InstCombine] [InstCombine] Canonicalize (-X s/ Y) to -(X s/ Y).
Differential Revision: https://reviews.llvm.org/D60395 llvm-svn: 358017
Diffstat (limited to 'llvm/lib/Transforms/InstCombine')
-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..2db6e849b19 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -1043,6 +1043,12 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
Value *NarrowOp = Builder.CreateSDiv(Op0Src, NarrowDivisor);
return new SExtInst(NarrowOp, Op0->getType());
}
+
+ // -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()));
// -X / C --> X / -C (if the negation doesn't overflow).
// TODO: This could be enhanced to handle arbitrary vector constants by
OpenPOWER on IntegriCloud