diff options
author | Chen Zheng <czhengsz@cn.ibm.com> | 2019-04-13 09:21:22 +0000 |
---|---|---|
committer | Chen Zheng <czhengsz@cn.ibm.com> | 2019-04-13 09:21:22 +0000 |
commit | 87dd0e06dc9920305b8f48dbc556721d01bbbd1e (patch) | |
tree | 143db0a31792eae7888dcaba70e60df54c7447b1 /llvm/lib/Transforms | |
parent | fc59a0326b7c8bf2cf91c0f03cbdd43983608b05 (diff) | |
download | bcm5719-llvm-87dd0e06dc9920305b8f48dbc556721d01bbbd1e.tar.gz bcm5719-llvm-87dd0e06dc9920305b8f48dbc556721d01bbbd1e.zip |
[InstCombine] Canonicalize (-X srem Y) to -(X srem Y).
Differential Revision: https://reviews.llvm.org/D60647
llvm-svn: 358328
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index e53eac2dd4e..7edae55cb3e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -1351,6 +1351,11 @@ Instruction *InstCombiner::visitSRem(BinaryOperator &I) { } } + // -X srem Y --> -(X srem Y) + Value *X, *Y; + if (match(&I, m_SRem(m_OneUse(m_NSWSub(m_Zero(), m_Value(X))), m_Value(Y)))) + return BinaryOperator::CreateNSWNeg(Builder.CreateSRem(X, Y)); + // If the sign bits of both operands are zero (i.e. we can prove they are // unsigned inputs), turn this into a urem. APInt Mask(APInt::getSignMask(I.getType()->getScalarSizeInBits())); |