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 | df5d7dcef10434340ae1b7384b3882d1659d9b10 (patch) | |
| tree | ac351eda6b1bdaa5f3989b69bb7d59abfad7e825 /llvm/lib | |
| parent | 71505aa4deea8cbd592724de37cee532a1267b61 (diff) | |
| download | bcm5719-llvm-df5d7dcef10434340ae1b7384b3882d1659d9b10.tar.gz bcm5719-llvm-df5d7dcef10434340ae1b7384b3882d1659d9b10.zip | |
Teach instcombine to promote alloca array sizes.
llvm-svn: 104945
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index 0f2a24f59bd..fd3d5347028 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/llvm/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())) { |

