diff options
author | Gil Rapaport <gil.rapaport@intel.com> | 2018-06-26 05:31:18 +0000 |
---|---|---|
committer | Gil Rapaport <gil.rapaport@intel.com> | 2018-06-26 05:31:18 +0000 |
commit | da2e2caa6c99ae067a26a0b56f976303be17d71c (patch) | |
tree | 654d72dd250671aea987ab424a14217609e79669 /llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | |
parent | 08dae1682d5f4590fa9dc0bc2ce8c614fef23579 (diff) | |
download | bcm5719-llvm-da2e2caa6c99ae067a26a0b56f976303be17d71c.tar.gz bcm5719-llvm-da2e2caa6c99ae067a26a0b56f976303be17d71c.zip |
[InstCombine] (A + 1) + (B ^ -1) --> A - B
Turn canonicalized subtraction back into (-1 - B) and combine it with (A + 1) into (A - B).
This is similar to the folding already done for (B ^ -1) + Const into (-1 + Const) - B.
Differential Revision: https://reviews.llvm.org/D48535
llvm-svn: 335579
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index 1101f729063..330db9eb91f 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1212,6 +1212,11 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { if (Value *V = checkForNegativeOperand(I, Builder)) return replaceInstUsesWith(I, V); + // (A + 1) + ~B --> A - B + // ~B + (A + 1) --> A - B + if (match(&I, m_c_BinOp(m_Add(m_Value(A), m_One()), m_Not(m_Value(B))))) + return BinaryOperator::CreateSub(A, B); + // X % C0 + (( X / C0 ) % C1) * C0 => X % (C0 * C1) if (Value *V = SimplifyAddWithRemainder(I)) return replaceInstUsesWith(I, V); |