Remove a special case, allowing the general case to handle it. No functionality

change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24076 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2005-10-29 03:19:53 +00:00
parent 167f1e2651
commit 455fcc8d35

View File

@ -3814,58 +3814,46 @@ Instruction *InstCombiner::PromoteCastOfAllocation(CastInst &CI,
uint64_t CastElTySize = TD->getTypeSize(CastElTy); uint64_t CastElTySize = TD->getTypeSize(CastElTy);
if (CastElTySize == 0 || AllocElTySize == 0) return 0; if (CastElTySize == 0 || AllocElTySize == 0) return 0;
// If the allocation is for an even multiple of the cast type size // See if we can satisfy the modulus by pulling a scale out of the array
Value *Amt = 0; // size argument.
if (AllocElTySize % CastElTySize == 0) { unsigned ArraySizeScale = 1;
Amt = ConstantUInt::get(Type::UIntTy, AllocElTySize/CastElTySize); Value *NumElements = AI.getOperand(0);
if (ConstantUInt *CI = dyn_cast<ConstantUInt>(AI.getOperand(0)))
Amt = ConstantExpr::getMul(CI, cast<ConstantUInt>(Amt)); if (ConstantUInt *CI = dyn_cast<ConstantUInt>(NumElements)) {
else { ArraySizeScale = CI->getValue();
// Perform an explicit scale. NumElements = ConstantUInt::get(Type::UIntTy, 1);
Instruction *Tmp = BinaryOperator::createMul(Amt, AI.getOperand(0),"tmp"); } else if (ShiftInst *SI = dyn_cast<ShiftInst>(NumElements)) {
Amt = InsertNewInstBefore(Tmp, AI); if (SI->getOpcode() == Instruction::Shl)
} if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(SI->getOperand(1))) {
} else { // This is a value scaled by '1 << the shift amt'.
// See if we can satisfy the modulus by pulling a scale out of the array NumElements = SI->getOperand(0);
// size argument. ArraySizeScale = 1U << CUI->getValue();
unsigned ArraySizeScale = 1;
Value *NumElements = AI.getOperand(0);
if (ConstantUInt *CI = dyn_cast<ConstantUInt>(NumElements)) {
ArraySizeScale = CI->getValue();
NumElements = ConstantUInt::get(Type::UIntTy, 1);
} else if (ShiftInst *SI = dyn_cast<ShiftInst>(NumElements)) {
if (SI->getOpcode() == Instruction::Shl)
if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(SI->getOperand(1))) {
// This is a value scaled by '1 << the shift amt'.
NumElements = SI->getOperand(0);
ArraySizeScale = 1U << CUI->getValue();
}
} else if (isa<Instruction>(NumElements) &&
cast<Instruction>(NumElements)->getOpcode() == Instruction::Mul){
BinaryOperator *BO = cast<BinaryOperator>(NumElements);
if (ConstantUInt *Scale = dyn_cast<ConstantUInt>(BO->getOperand(1))) {
// This value is scaled by 'Scale'.
NumElements = BO->getOperand(0);
ArraySizeScale = Scale->getValue();
} }
} else if (isa<Instruction>(NumElements) &&
cast<Instruction>(NumElements)->getOpcode() == Instruction::Mul){
BinaryOperator *BO = cast<BinaryOperator>(NumElements);
if (ConstantUInt *Scale = dyn_cast<ConstantUInt>(BO->getOperand(1))) {
// This value is scaled by 'Scale'.
NumElements = BO->getOperand(0);
ArraySizeScale = Scale->getValue();
} }
}
// If we can now satisfy the modulus, by using a non-1 scale, we really can
// do the xform. // If we can now satisfy the modulus, by using a non-1 scale, we really can
if ((AllocElTySize*ArraySizeScale) % CastElTySize != 0) return 0; // do the xform.
if ((AllocElTySize*ArraySizeScale) % CastElTySize != 0) return 0;
unsigned Scale = (AllocElTySize*ArraySizeScale)/CastElTySize; unsigned Scale = (AllocElTySize*ArraySizeScale)/CastElTySize;
if (Scale == 1) { Value *Amt = 0;
Amt = NumElements; if (Scale == 1) {
} else { Amt = NumElements;
Amt = ConstantUInt::get(Type::UIntTy, Scale); } else {
if (ConstantUInt *CI = dyn_cast<ConstantUInt>(NumElements)) Amt = ConstantUInt::get(Type::UIntTy, Scale);
Amt = ConstantExpr::getMul(CI, cast<ConstantUInt>(Amt)); if (ConstantUInt *CI = dyn_cast<ConstantUInt>(NumElements))
else if (Scale != 1) { Amt = ConstantExpr::getMul(CI, cast<ConstantUInt>(Amt));
Instruction *Tmp = BinaryOperator::createMul(Amt, NumElements, "tmp"); else if (Scale != 1) {
Amt = InsertNewInstBefore(Tmp, AI); Instruction *Tmp = BinaryOperator::createMul(Amt, NumElements, "tmp");
} Amt = InsertNewInstBefore(Tmp, AI);
} }
} }