From 455fcc8d3579c84aa0c2b876482983eb2f81bc7d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 29 Oct 2005 03:19:53 +0000 Subject: [PATCH] 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 --- .../Scalar/InstructionCombining.cpp | 86 ++++++++----------- 1 file changed, 37 insertions(+), 49 deletions(-) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index e029f7a6571..0c1f52ea02d 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -3814,58 +3814,46 @@ Instruction *InstCombiner::PromoteCastOfAllocation(CastInst &CI, uint64_t CastElTySize = TD->getTypeSize(CastElTy); if (CastElTySize == 0 || AllocElTySize == 0) return 0; - // If the allocation is for an even multiple of the cast type size - Value *Amt = 0; - if (AllocElTySize % CastElTySize == 0) { - Amt = ConstantUInt::get(Type::UIntTy, AllocElTySize/CastElTySize); - if (ConstantUInt *CI = dyn_cast(AI.getOperand(0))) - Amt = ConstantExpr::getMul(CI, cast(Amt)); - else { - // Perform an explicit scale. - Instruction *Tmp = BinaryOperator::createMul(Amt, AI.getOperand(0),"tmp"); - Amt = InsertNewInstBefore(Tmp, AI); - } - } else { - // See if we can satisfy the modulus by pulling a scale out of the array - // size argument. - unsigned ArraySizeScale = 1; - Value *NumElements = AI.getOperand(0); - - if (ConstantUInt *CI = dyn_cast(NumElements)) { - ArraySizeScale = CI->getValue(); - NumElements = ConstantUInt::get(Type::UIntTy, 1); - } else if (ShiftInst *SI = dyn_cast(NumElements)) { - if (SI->getOpcode() == Instruction::Shl) - if (ConstantUInt *CUI = dyn_cast(SI->getOperand(1))) { - // This is a value scaled by '1 << the shift amt'. - NumElements = SI->getOperand(0); - ArraySizeScale = 1U << CUI->getValue(); - } - } else if (isa(NumElements) && - cast(NumElements)->getOpcode() == Instruction::Mul){ - BinaryOperator *BO = cast(NumElements); - if (ConstantUInt *Scale = dyn_cast(BO->getOperand(1))) { - // This value is scaled by 'Scale'. - NumElements = BO->getOperand(0); - ArraySizeScale = Scale->getValue(); + // See if we can satisfy the modulus by pulling a scale out of the array + // size argument. + unsigned ArraySizeScale = 1; + Value *NumElements = AI.getOperand(0); + + if (ConstantUInt *CI = dyn_cast(NumElements)) { + ArraySizeScale = CI->getValue(); + NumElements = ConstantUInt::get(Type::UIntTy, 1); + } else if (ShiftInst *SI = dyn_cast(NumElements)) { + if (SI->getOpcode() == Instruction::Shl) + if (ConstantUInt *CUI = dyn_cast(SI->getOperand(1))) { + // This is a value scaled by '1 << the shift amt'. + NumElements = SI->getOperand(0); + ArraySizeScale = 1U << CUI->getValue(); } + } else if (isa(NumElements) && + cast(NumElements)->getOpcode() == Instruction::Mul){ + BinaryOperator *BO = cast(NumElements); + if (ConstantUInt *Scale = dyn_cast(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 ((AllocElTySize*ArraySizeScale) % CastElTySize != 0) return 0; + } + + // If we can now satisfy the modulus, by using a non-1 scale, we really can + // do the xform. + if ((AllocElTySize*ArraySizeScale) % CastElTySize != 0) return 0; - unsigned Scale = (AllocElTySize*ArraySizeScale)/CastElTySize; - if (Scale == 1) { - Amt = NumElements; - } else { - Amt = ConstantUInt::get(Type::UIntTy, Scale); - if (ConstantUInt *CI = dyn_cast(NumElements)) - Amt = ConstantExpr::getMul(CI, cast(Amt)); - else if (Scale != 1) { - Instruction *Tmp = BinaryOperator::createMul(Amt, NumElements, "tmp"); - Amt = InsertNewInstBefore(Tmp, AI); - } + unsigned Scale = (AllocElTySize*ArraySizeScale)/CastElTySize; + Value *Amt = 0; + if (Scale == 1) { + Amt = NumElements; + } else { + Amt = ConstantUInt::get(Type::UIntTy, Scale); + if (ConstantUInt *CI = dyn_cast(NumElements)) + Amt = ConstantExpr::getMul(CI, cast(Amt)); + else if (Scale != 1) { + Instruction *Tmp = BinaryOperator::createMul(Amt, NumElements, "tmp"); + Amt = InsertNewInstBefore(Tmp, AI); } }