diff options
author | Sanjay Patel <spatel@rotateright.com> | 2017-10-13 16:29:38 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2017-10-13 16:29:38 +0000 |
commit | 2150651ac3192a4f560057adda8c6b0e4df2b685 (patch) | |
tree | 75216c0b71e6423f692d894cf48c5da6e68f8a49 /llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | |
parent | 08fb414b215a6b3ef07c365d7d18360e6811d1f2 (diff) | |
download | bcm5719-llvm-2150651ac3192a4f560057adda8c6b0e4df2b685.tar.gz bcm5719-llvm-2150651ac3192a4f560057adda8c6b0e4df2b685.zip |
[InstCombine] allow zext(bool) + C --> select bool, C+1, C for vector types
The backend should be prepared for this transform after:
https://reviews.llvm.org/rL311731
llvm-svn: 315701
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index bcd60bca177..e12bff01376 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -953,6 +953,19 @@ static Value *checkForNegativeOperand(BinaryOperator &I, static Instruction *foldAddWithConstant(BinaryOperator &Add, InstCombiner::BuilderTy &Builder) { Value *Op0 = Add.getOperand(0), *Op1 = Add.getOperand(1); + Constant *Op1C; + if (!match(Op1, m_Constant(Op1C))) + return nullptr; + + Value *X; + Type *Ty = Add.getType(); + if (match(Op0, m_ZExt(m_Value(X))) && + X->getType()->getScalarSizeInBits() == 1) { + // zext(bool) + C -> bool ? C + 1 : C + Constant *One = ConstantInt::get(Ty, 1); + return SelectInst::Create(X, ConstantExpr::getAdd(Op1C, One), Op1); + } + const APInt *C; if (!match(Op1, m_APInt(C))) return nullptr; @@ -968,12 +981,9 @@ static Instruction *foldAddWithConstant(BinaryOperator &Add, return BinaryOperator::CreateXor(Op0, Op1); } - Value *X; - const APInt *C2; - Type *Ty = Add.getType(); - // Is this add the last step in a convoluted sext? // add(zext(xor i16 X, -32768), -32768) --> sext X + const APInt *C2; if (match(Op0, m_ZExt(m_Xor(m_Value(X), m_APInt(C2)))) && C2->isMinSignedValue() && C2->sext(Ty->getScalarSizeInBits()) == *C) return CastInst::Create(Instruction::SExt, X, Ty); @@ -1031,13 +1041,8 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { return X; // FIXME: This should be moved into the above helper function to allow these - // transforms for splat vectors. + // transforms for general constant or constant splat vectors. if (ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) { - // zext(bool) + C -> bool ? C + 1 : C - if (ZExtInst *ZI = dyn_cast<ZExtInst>(LHS)) - if (ZI->getSrcTy()->isIntegerTy(1)) - return SelectInst::Create(ZI->getOperand(0), AddOne(CI), CI); - Value *XorLHS = nullptr; ConstantInt *XorRHS = nullptr; if (match(LHS, m_Xor(m_Value(XorLHS), m_ConstantInt(XorRHS)))) { uint32_t TySizeBits = I.getType()->getScalarSizeInBits(); |