diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-06-26 20:32:52 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-06-26 20:32:52 +0000 | 
| commit | 08bbd35a80bf7765fe0d3043f9eb5a2f2786b649 (patch) | |
| tree | 80108f0f128657f8623f8f66ad9735b4d88e7b47 /lib/Transforms/InstCombine/InstCombineAddSub.cpp | |
| parent | 7c7aba6e5fef47a01a136be655b0a92cfd7090f6 (diff) | |
Notes
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineAddSub.cpp')
| -rw-r--r-- | lib/Transforms/InstCombine/InstCombineAddSub.cpp | 27 | 
1 files changed, 18 insertions, 9 deletions
| diff --git a/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/lib/Transforms/InstCombine/InstCombineAddSub.cpp index 287a5167fe2a..d5f0dd191415 100644 --- a/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -988,15 +988,24 @@ static Instruction *foldAddWithConstant(BinaryOperator &Add,      return new ZExtInst(Builder.CreateNUWAdd(X, NewC), Ty);    } -  // Shifts and add used to flip and mask off the low bit: -  // add (ashr (shl i32 X, 31), 31), 1 --> and (not X), 1 -  const APInt *C3; -  if (C->isOneValue() && -      match(Op0, -            m_OneUse(m_AShr(m_Shl(m_Value(X), m_APInt(C2)), m_APInt(C3)))) && -      C2 == C3 && *C2 == Ty->getScalarSizeInBits() - 1) { -    Value *NotX = Builder.CreateNot(X); -    return BinaryOperator::CreateAnd(NotX, ConstantInt::get(Ty, 1)); +  if (C->isOneValue() && Op0->hasOneUse()) { +    // add (sext i1 X), 1 --> zext (not X) +    // TODO: The smallest IR representation is (select X, 0, 1), and that would +    // not require the one-use check. But we need to remove a transform in +    // visitSelect and make sure that IR value tracking for select is equal or +    // better than for these ops. +    if (match(Op0, m_SExt(m_Value(X))) && +        X->getType()->getScalarSizeInBits() == 1) +      return new ZExtInst(Builder.CreateNot(X), Ty); + +    // Shifts and add used to flip and mask off the low bit: +    // add (ashr (shl i32 X, 31), 31), 1 --> and (not X), 1 +    const APInt *C3; +    if (match(Op0, m_AShr(m_Shl(m_Value(X), m_APInt(C2)), m_APInt(C3))) && +        C2 == C3 && *C2 == Ty->getScalarSizeInBits() - 1) { +      Value *NotX = Builder.CreateNot(X); +      return BinaryOperator::CreateAnd(NotX, ConstantInt::get(Ty, 1)); +    }    }    return nullptr; | 
