[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Zhou Sheng zhousheng00 at gmail.com
Wed Mar 28 18:57:39 PDT 2007



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.705 -> 1.706
---
Log message:

1. Make the APInt variable do the binary operation stuff if possible
   instead of using ConstantExpr::getXX.
2. Use constant reference to APInt if possible instead of expensive
   APInt copy.


---
Diffs of the changes:  (+5 -3)

 InstructionCombining.cpp |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.705 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.706
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.705	Wed Mar 28 12:38:21 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Wed Mar 28 20:57:21 2007
@@ -540,8 +540,10 @@
       if (I->getOpcode() == Instruction::Shl)
         if ((CST = dyn_cast<ConstantInt>(I->getOperand(1)))) {
           // The multiplier is really 1 << CST.
-          Constant *One = ConstantInt::get(V->getType(), 1);
-          CST = cast<ConstantInt>(ConstantExpr::getShl(One, CST));
+          uint32_t BitWidth = cast<IntegerType>(V->getType())->getBitWidth();
+          uint32_t CSTVal = CST->getValue().getActiveBits() > 64 ?
+                              BitWidth : CST->getZExtValue();
+          CST = ConstantInt::get(APInt(BitWidth, 1).shl(CSTVal));
           return I->getOperand(0);
         }
     }
@@ -2264,7 +2266,7 @@
       if (CI->isAllOnesValue())              // X * -1 == 0 - X
         return BinaryOperator::createNeg(Op0, I.getName());
 
-      APInt Val(cast<ConstantInt>(CI)->getValue());
+      const APInt& Val = cast<ConstantInt>(CI)->getValue();
       if (Val.isPowerOf2()) {          // Replace X*(2^C) with X << C
         return BinaryOperator::createShl(Op0,
                  ConstantInt::get(Op0->getType(), Val.logBase2()));






More information about the llvm-commits mailing list