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 | eb8905055faab349a8f7c672cadd732a5a36aa2e (patch) | |
| tree | 034b7c3e0cc5b4d78be0ed62edce04ac9cb2af75 /lib/Transforms | |
| parent | 1aa07da87a8d8f99c1647af14b3a135a135996fe (diff) | |
| download | external_llvm-eb8905055faab349a8f7c672cadd732a5a36aa2e.zip external_llvm-eb8905055faab349a8f7c672cadd732a5a36aa2e.tar.gz external_llvm-eb8905055faab349a8f7c672cadd732a5a36aa2e.tar.bz2 | |
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')
| -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 0f2a24f..fd3d534 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())) { |
