summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-07-28 16:48:44 +0000
committerSanjay Patel <spatel@rotateright.com>2018-07-28 16:48:44 +0000
commit818b253d3a33e4881b5378beee1fa72a0bece912 (patch)
tree4e2a50682ef795d3c2989882d7a8ce112a2e9764 /llvm/lib/Transforms
parent376051820d17cdc2feccb1878896d571db07f068 (diff)
downloadbcm5719-llvm-818b253d3a33e4881b5378beee1fa72a0bece912.tar.gz
bcm5719-llvm-818b253d3a33e4881b5378beee1fa72a0bece912.zip
[InstCombine] try to fold 'sub' to 'not'
https://rise4fun.com/Alive/jDd Patterns with add/sub combos can be improved using 'not' ops. This is better for analysis and may lead to follow-on transforms because 'xor' and 'add' are commutative/associative. It can also help codegen. llvm-svn: 338200
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index aa31e0d850d..e79bdf75d40 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -926,7 +926,13 @@ Instruction *InstCombiner::foldAddWithConstant(BinaryOperator &Add) {
if (Instruction *NV = foldBinOpIntoSelectOrPhi(Add))
return NV;
- Value *X;
+ Value *X, *Y;
+
+ // add (sub X, Y), -1 --> add (not Y), X
+ if (match(Op0, m_OneUse(m_Sub(m_Value(X), m_Value(Y)))) &&
+ match(Op1, m_AllOnes()))
+ return BinaryOperator::CreateAdd(Builder.CreateNot(Y), X);
+
// zext(bool) + C -> bool ? C + 1 : C
if (match(Op0, m_ZExt(m_Value(X))) &&
X->getType()->getScalarSizeInBits() == 1)
OpenPOWER on IntegriCloud