diff options
| author | Roman Lebedev <lebedev.ri@gmail.com> | 2019-05-31 09:47:04 +0000 |
|---|---|---|
| committer | Roman Lebedev <lebedev.ri@gmail.com> | 2019-05-31 09:47:04 +0000 |
| commit | 886c4ef35aacefd33dab1d1b674a872d08036f00 (patch) | |
| tree | 22c66d4acda6ff6bb73fe01b4205095d5d038258 /llvm/lib | |
| parent | 0fc3a0739850fd84ec910046b90514d0c97f2420 (diff) | |
| download | bcm5719-llvm-886c4ef35aacefd33dab1d1b674a872d08036f00.tar.gz bcm5719-llvm-886c4ef35aacefd33dab1d1b674a872d08036f00.zip | |
[InstCombine] 'add (sub C1, X), C2 --> sub (add C1, C2), X' constant-fold
https://rise4fun.com/Alive/qJQ
llvm-svn: 362216
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index 2d608e74b69..d422b07d49f 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -872,7 +872,14 @@ Instruction *InstCombiner::foldAddWithConstant(BinaryOperator &Add) { if (Instruction *NV = foldBinOpIntoSelectOrPhi(Add)) return NV; - Value *X, *Y; + Value *X; + Constant *Op00C; + + // add (sub C1, X), C2 --> sub (add C1, C2), X + if (match(Op0, m_Sub(m_Constant(Op00C), m_Value(X)))) + return BinaryOperator::CreateSub(ConstantExpr::getAdd(Op00C, Op1C), X); + + Value *Y; // add (sub X, Y), -1 --> add (not Y), X if (match(Op0, m_OneUse(m_Sub(m_Value(X), m_Value(Y)))) && |

