mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-16 08:08:01 +00:00
Fold:
(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] llvm-svn: 17701
This commit is contained in:
parent
d348f5b9fb
commit
7a8d26a581
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user