mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-13 10:32:06 +00:00
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35443 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ab47895c6b
commit
97b52c260f
@ -540,8 +540,10 @@ static inline Value *dyn_castFoldableMul(Value *V, ConstantInt *&CST) {
|
|||||||
if (I->getOpcode() == Instruction::Shl)
|
if (I->getOpcode() == Instruction::Shl)
|
||||||
if ((CST = dyn_cast<ConstantInt>(I->getOperand(1)))) {
|
if ((CST = dyn_cast<ConstantInt>(I->getOperand(1)))) {
|
||||||
// The multiplier is really 1 << CST.
|
// The multiplier is really 1 << CST.
|
||||||
Constant *One = ConstantInt::get(V->getType(), 1);
|
uint32_t BitWidth = cast<IntegerType>(V->getType())->getBitWidth();
|
||||||
CST = cast<ConstantInt>(ConstantExpr::getShl(One, CST));
|
uint32_t CSTVal = CST->getValue().getActiveBits() > 64 ?
|
||||||
|
BitWidth : CST->getZExtValue();
|
||||||
|
CST = ConstantInt::get(APInt(BitWidth, 1).shl(CSTVal));
|
||||||
return I->getOperand(0);
|
return I->getOperand(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2264,7 +2266,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
|
|||||||
if (CI->isAllOnesValue()) // X * -1 == 0 - X
|
if (CI->isAllOnesValue()) // X * -1 == 0 - X
|
||||||
return BinaryOperator::createNeg(Op0, I.getName());
|
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
|
if (Val.isPowerOf2()) { // Replace X*(2^C) with X << C
|
||||||
return BinaryOperator::createShl(Op0,
|
return BinaryOperator::createShl(Op0,
|
||||||
ConstantInt::get(Op0->getType(), Val.logBase2()));
|
ConstantInt::get(Op0->getType(), Val.logBase2()));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user