summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-10-27 05:53:56 +0000
committerChris Lattner <sabre@nondot.org>2005-10-27 05:53:56 +0000
commitbb17180a23201580f89ec7a416a98299164d5ae8 (patch)
tree96d60330a162cf6c585e5ad02bd0e6e9277a319d /llvm/lib/Transforms
parentd8c5c066a161b544d47c804251c6eda9ff97899f (diff)
downloadbcm5719-llvm-bb17180a23201580f89ec7a416a98299164d5ae8.tar.gz
bcm5719-llvm-bb17180a23201580f89ec7a416a98299164d5ae8.zip
Minor change to this file to support obscure cases with constant array amounts
llvm-svn: 24030
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index f3325096895..a5a2597a2f6 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -1709,7 +1709,6 @@ Value *InstCombiner::FoldLogicalPlusAnd(Value *LHS, Value *RHS,
return InsertNewInstBefore(New, I);
}
-
Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
bool Changed = SimplifyCommutative(I);
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
@@ -3776,7 +3775,7 @@ Value *InstCombiner::InsertOperandCastBefore(Value *V, const Type *DestTy,
Instruction *InstCombiner::PromoteCastOfAllocation(CastInst &CI,
AllocationInst &AI) {
const PointerType *PTy = dyn_cast<PointerType>(CI.getType());
- if (AI.isArrayAllocation() || !PTy) return 0;
+ if (!PTy) return 0; // Not casting the allocation to a pointer type.
// Remove any uses of AI that are dead.
assert(!CI.use_empty() && "Dead instructions should be removed earlier!");
@@ -3813,12 +3812,23 @@ Instruction *InstCombiner::PromoteCastOfAllocation(CastInst &CI,
uint64_t AllocElTySize = TD->getTypeSize(AllocElTy);
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
- if (CastElTySize == 0 || AllocElTySize % CastElTySize != 0)
+ Value *Amt = 0;
+ if (AllocElTySize % CastElTySize == 0) {
+ Amt = ConstantUInt::get(Type::UIntTy, AllocElTySize/CastElTySize);
+ if (ConstantUInt *CI = dyn_cast<ConstantUInt>(AI.getOperand(0)))
+ Amt = ConstantExpr::getMul(CI, cast<ConstantUInt>(Amt));
+ else {
+ // Perform an explicit scale.
+ Instruction *Tmp = BinaryOperator::createMul(Amt, AI.getOperand(0),"tmp");
+ Amt = InsertNewInstBefore(Tmp, AI);
+ }
+ } else {
return 0;
- Value *Amt = ConstantUInt::get(Type::UIntTy,
- AllocElTySize/CastElTySize);
+ }
+
std::string Name = AI.getName(); AI.setName("");
AllocationInst *New;
if (isa<MallocInst>(AI))
@@ -4061,6 +4071,7 @@ Instruction *InstCombiner::visitCastInst(CastInst &CI) {
break;
}
}
+
return 0;
}
OpenPOWER on IntegriCloud