summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2019-05-31 09:47:16 +0000
committerRoman Lebedev <lebedev.ri@gmail.com>2019-05-31 09:47:16 +0000
commit39390d8317003ffc0627a30ae913bba3b3616efb (patch)
tree58fc645808b33f13107a1c1ac6c0d63f7c484863 /llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
parent886c4ef35aacefd33dab1d1b674a872d08036f00 (diff)
downloadbcm5719-llvm-39390d8317003ffc0627a30ae913bba3b3616efb.tar.gz
bcm5719-llvm-39390d8317003ffc0627a30ae913bba3b3616efb.zip
[InstCombine] 'C-(C2-X) --> X+(C-C2)' constant-fold
It looks this fold was already partially happening, indirectly via some other folds, but with one-use limitation. No other fold here has that restriction. https://rise4fun.com/Alive/ftR llvm-svn: 362217
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index d422b07d49f..e6b32ba13a4 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1609,8 +1609,13 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
if (Instruction *R = foldOpIntoPhi(I, PN))
return R;
- // C-(X+C2) --> (C-C2)-X
Constant *C2;
+
+ // C-(C2-X) --> X+(C-C2)
+ if (match(Op1, m_Sub(m_Constant(C2), m_Value(X))))
+ return BinaryOperator::CreateAdd(X, ConstantExpr::getSub(C, C2));
+
+ // C-(X+C2) --> (C-C2)-X
if (match(Op1, m_Add(m_Value(X), m_Constant(C2))))
return BinaryOperator::CreateSub(ConstantExpr::getSub(C, C2), X);
}
OpenPOWER on IntegriCloud