From 4961cf1c064af62f5bbb3f8a86e0ef0c2e45beb7 Mon Sep 17 00:00:00 2001 From: Zhou Sheng Date: Thu, 29 Mar 2007 01:57:21 +0000 Subject: [PATCH] 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. llvm-svn: 35443 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index d72783a0de69..0c49647281b5 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -540,8 +540,10 @@ static inline Value *dyn_castFoldableMul(Value *V, ConstantInt *&CST) { if (I->getOpcode() == Instruction::Shl) if ((CST = dyn_cast(I->getOperand(1)))) { // The multiplier is really 1 << CST. - Constant *One = ConstantInt::get(V->getType(), 1); - CST = cast(ConstantExpr::getShl(One, CST)); + uint32_t BitWidth = cast(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 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { if (CI->isAllOnesValue()) // X * -1 == 0 - X return BinaryOperator::createNeg(Op0, I.getName()); - APInt Val(cast(CI)->getValue()); + const APInt& Val = cast(CI)->getValue(); if (Val.isPowerOf2()) { // Replace X*(2^C) with X << C return BinaryOperator::createShl(Op0, ConstantInt::get(Op0->getType(), Val.logBase2()));