diff options
author | Dan Gohman <gohman@apple.com> | 2010-05-28 15:09:00 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-05-28 15:09:00 +0000 |
commit | 05d62537276197b3351d9887f4967590b6a3b901 (patch) | |
tree | 034b7c3e0cc5b4d78be0ed62edce04ac9cb2af75 /lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp | |
parent | 8496d504127747d0fd44359b4936315abade7f1a (diff) | |
download | llvm-05d62537276197b3351d9887f4967590b6a3b901.tar.gz llvm-05d62537276197b3351d9887f4967590b6a3b901.tar.bz2 llvm-05d62537276197b3351d9887f4967590b6a3b901.tar.xz |
Teach instcombine to promote alloca array sizes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104945 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index 0f2a24f59b..fd3d534702 100644 --- a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -22,6 +22,18 @@ using namespace llvm; STATISTIC(NumDeadStore, "Number of dead stores eliminated"); Instruction *InstCombiner::visitAllocaInst(AllocaInst &AI) { + // Ensure that the alloca array size argument has type intptr_t, so that + // any casting is exposed early. + if (TD) { + const Type *IntPtrTy = TD->getIntPtrType(AI.getContext()); + if (AI.getArraySize()->getType() != IntPtrTy) { + Value *V = Builder->CreateIntCast(AI.getArraySize(), + IntPtrTy, false); + AI.setOperand(0, V); + return &AI; + } + } + // Convert: alloca Ty, C - where C is a constant != 1 into: alloca [C x Ty], 1 if (AI.isArrayAllocation()) { // Check C != 1 if (const ConstantInt *C = dyn_cast<ConstantInt>(AI.getArraySize())) { |