[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sat Nov 13 11:31:54 PST 2004
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.279 -> 1.280
---
Log message:
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]
---
Diffs of the changes: (+13 -0)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.279 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.280
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.279 Thu Nov 4 22:45:43 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sat Nov 13 13:31:40 2004
@@ -618,6 +618,19 @@
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
More information about the llvm-commits
mailing list