From 5e13ff1da20bf02bbb256b2006dcbb42e06d300e Mon Sep 17 00:00:00 2001 From: Chen Zheng Date: Wed, 10 Apr 2019 06:52:09 +0000 Subject: [InstCombine] Canonicalize (-X s/ Y) to -(X s/ Y). Differential Revision: https://reviews.llvm.org/D60395 llvm-svn: 358050 --- llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'llvm/lib') 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())); -- cgit v1.2.3