(X + (X << C2)) --> X * ((1 << C2) + 1)
   ((X << C2) + X) --> X * ((1 << C2) + 1)

This means that we now canonicalize "Y+Y+Y" into:

        %tmp.2 = mul long %Y, 3         ; <long> [#uses=1]

instead of:

        %tmp.10 = shl long %Y, ubyte 1          ; <long> [#uses=1]
        %tmp.6 = add long %Y, %tmp.10               ; <long> [#uses=1]


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17701 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2004-11-13 19:31:40 +00:00
parent 0c3b390a54
commit 65aedc1a4e

View File

@ -618,6 +618,19 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
if (match(RHS, m_And(m_Value(), m_ConstantInt(C2))))
if (Instruction *R = AssociativeOpt(I, AddMaskingAnd(C2))) return R;
// (X + (X << C2)) --> X * ((1 << C2) + 1)
// ((X << C2) + X) --> X * ((1 << C2) + 1)
Value *Tmp;
if ((RHS->hasOneUse() && match(RHS, m_Shl(m_Value(Tmp),
m_ConstantInt(C2))) && LHS == Tmp)||
(LHS->hasOneUse() && match(LHS, m_Shl(m_Value(Tmp),
m_ConstantInt(C2))) && RHS == Tmp)){
ConstantInt *One = ConstantInt::get(LHS->getType(), 1);
Constant *NewRHS =
ConstantExpr::getAdd(ConstantExpr::getShl(One, C2), One);
return BinaryOperator::createMul(Tmp, NewRHS);
}
if (ConstantInt *CRHS = dyn_cast<ConstantInt>(RHS)) {
Value *X;
if (match(LHS, m_Not(m_Value(X)))) { // ~X + C --> (C-1) - X