diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-09-02 19:31:45 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-09-02 19:31:45 +0000 |
commit | 17e709b66ac01f097e124ab058f0e483b597492d (patch) | |
tree | 7e5b4eaf3cc42267cdd50a77e1bfa8d809aca0e5 /llvm/lib/Transforms | |
parent | 04ab22b3f40968ddf9484d39a273433c9f2fc532 (diff) | |
download | bcm5719-llvm-17e709b66ac01f097e124ab058f0e483b597492d.tar.gz bcm5719-llvm-17e709b66ac01f097e124ab058f0e483b597492d.zip |
[InstCombine] allow not+sub fold for arbitrary vector constants
The fold was implemented for the general case but use-limitation,
but the later constant version which didn't check uses was only
matching splat constants.
llvm-svn: 341292
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 7b8c1db77ce..f34ec13f02e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2673,8 +2673,9 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { } // ~(X - Y) --> ~X + Y - if (match(NotVal, m_OneUse(m_Sub(m_Value(X), m_Value(Y))))) - return BinaryOperator::CreateAdd(Builder.CreateNot(X), Y); + if (match(NotVal, m_Sub(m_Value(X), m_Value(Y)))) + if (isa<Constant>(X) || NotVal->hasOneUse()) + return BinaryOperator::CreateAdd(Builder.CreateNot(X), Y); // ~(~X >>s Y) --> (X >>s Y) if (match(NotVal, m_AShr(m_Not(m_Value(X)), m_Value(Y)))) @@ -2713,18 +2714,13 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { Value *X; const APInt *C; if (match(Op0, m_Sub(m_APInt(C), m_Value(X)))) { - // ~(c-X) == X-c-1 == X+(-c-1) - if (RHSC->isAllOnesValue()) { - Constant *NewC = ConstantInt::get(I.getType(), -(*C) - 1); - return BinaryOperator::CreateAdd(X, NewC); - } if (RHSC->isSignMask()) { // (C - X) ^ signmask -> (C + signmask - X) Constant *NewC = ConstantInt::get(I.getType(), *C + *RHSC); return BinaryOperator::CreateSub(NewC, X); } } else if (match(Op0, m_Add(m_Value(X), m_APInt(C)))) { - // ~(X-c) --> (-c-1)-X + // ~(X + C) --> (-C - 1) - X if (RHSC->isAllOnesValue()) { Constant *NewC = ConstantInt::get(I.getType(), -(*C) - 1); return BinaryOperator::CreateSub(NewC, X); |