diff options
author | Craig Topper <craig.topper@intel.com> | 2017-08-06 06:28:41 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@intel.com> | 2017-08-06 06:28:41 +0000 |
commit | b5bf016015a5e2d224042eca02576a896318966f (patch) | |
tree | ead43f8037d8cb34c2d3e983eb0f5ed24ea7eaf4 /llvm/lib | |
parent | 5b307cdb8a788c3c707dde4789720fbcff5d34e0 (diff) | |
download | bcm5719-llvm-b5bf016015a5e2d224042eca02576a896318966f.tar.gz bcm5719-llvm-b5bf016015a5e2d224042eca02576a896318966f.zip |
[InstCombine] Support ~(c-X) --> X+(-c-1) and ~(X-c) --> (-c-1)-X for splat vectors.
llvm-svn: 310195
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 7b32812a2c1..e684f58f0f4 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2419,17 +2419,33 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { return replaceInstUsesWith(I, Op0); } + { + const APInt *RHSC; + if (match(Op1, m_APInt(RHSC))) { + Value *V; + const APInt *C; + if (match(Op0, m_Sub(m_APInt(C), m_Value(V)))) { + // ~(c-X) == X-c-1 == X+(-c-1) + if (RHSC->isAllOnesValue()) { + Constant *NewC = ConstantInt::get(I.getType(), -(*C) - 1); + return BinaryOperator::CreateAdd(V, NewC); + } + } else if (match(Op0, m_Add(m_Value(V), m_APInt(C)))) { + // ~(X-c) --> (-c-1)-X + if (RHSC->isAllOnesValue()) { + Constant *NewC = ConstantInt::get(I.getType(), -(*C) - 1); + return BinaryOperator::CreateSub(NewC, V); + } + } + } + } + if (ConstantInt *RHSC = dyn_cast<ConstantInt>(Op1)) { if (BinaryOperator *Op0I = dyn_cast<BinaryOperator>(Op0)) { - // ~(c-X) == X-c-1 == X+(-c-1) if (Op0I->getOpcode() == Instruction::Sub) if (ConstantInt *Op0I0C = dyn_cast<ConstantInt>(Op0I->getOperand(0))) { - if (RHSC->isMinusOne()) { - Constant *NegOp0I0C = ConstantExpr::getNeg(Op0I0C); - return BinaryOperator::CreateAdd(Op0I->getOperand(1), - SubOne(NegOp0I0C)); - } else if (RHSC->getValue().isSignMask()) { - // (C - X) ^ signmask -> (C + signmask - X) + // (C - X) ^ signmask -> (C + signmask - X) + if (RHSC->getValue().isSignMask()) { Constant *C = Builder.getInt(RHSC->getValue() + Op0I0C->getValue()); return BinaryOperator::CreateSub(C, Op0I->getOperand(1)); } @@ -2437,13 +2453,8 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { if (ConstantInt *Op0CI = dyn_cast<ConstantInt>(Op0I->getOperand(1))) { if (Op0I->getOpcode() == Instruction::Add) { - // ~(X-c) --> (-c-1)-X - if (RHSC->isMinusOne()) { - Constant *NegOp0CI = ConstantExpr::getNeg(Op0CI); - return BinaryOperator::CreateSub(SubOne(NegOp0CI), - Op0I->getOperand(0)); - } else if (RHSC->getValue().isSignMask()) { - // (X + C) ^ signmask -> (X + C + signmask) + // (X + C) ^ signmask -> (X + C + signmask) + if (RHSC->getValue().isSignMask()) { Constant *C = Builder.getInt(RHSC->getValue() + Op0CI->getValue()); return BinaryOperator::CreateAdd(Op0I->getOperand(0), C); } |