diff options
| author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-03-13 19:42:09 +0000 |
|---|---|---|
| committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-03-13 19:42:09 +0000 |
| commit | be95b4afc6d073677858f0751b74ab8917f5ae34 (patch) | |
| tree | d1d4f3314b3a340ee8339225369aecc70c3e5603 /llvm | |
| parent | 07ff9b03f6bf750e491cdde73f943a65f58f0d80 (diff) | |
| download | bcm5719-llvm-be95b4afc6d073677858f0751b74ab8917f5ae34.tar.gz bcm5719-llvm-be95b4afc6d073677858f0751b74ab8917f5ae34.zip | |
instcombine: alloca: Canonicalize scalar allocation array size
As a follow-up to r232200, add an `-instcombine` to canonicalize scalar
allocations to `i32 1`. Since r232200, `iX 1` (for X != 32) are only
created by RAUWs, so this shouldn't fire too often. Nevertheless, it's
a cheap check and a nice cleanup.
llvm-svn: 232202
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp | 12 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/alloca.ll | 4 |
2 files changed, 12 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index deed58c425e..73dd40e4d19 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -166,8 +166,16 @@ isOnlyCopiedFromConstantGlobal(AllocaInst *AI, static Instruction *simplifyAllocaArraySize(InstCombiner &IC, AllocaInst &AI) { // Check for array size of 1 (scalar allocation). - if (!AI.isArrayAllocation()) - return nullptr; + if (!AI.isArrayAllocation()) { + // i32 1 is the canonical array size for scalar allocations. + if (AI.getArraySize()->getType()->isIntegerTy(32)) + return nullptr; + + // Canonicalize it. + Value *V = IC.Builder->getInt32(1); + AI.setOperand(0, V); + return &AI; + } // Convert: alloca Ty, C - where C is a constant != 1 into: alloca [C x Ty], 1 if (const ConstantInt *C = dyn_cast<ConstantInt>(AI.getArraySize())) { diff --git a/llvm/test/Transforms/InstCombine/alloca.ll b/llvm/test/Transforms/InstCombine/alloca.ll index db26218f3b8..81e2083204b 100644 --- a/llvm/test/Transforms/InstCombine/alloca.ll +++ b/llvm/test/Transforms/InstCombine/alloca.ll @@ -155,8 +155,8 @@ define void @test10() { entry: ; ALL-LABEL: @test10( ; ALL: %v32 = alloca i1, align 8 -; ALL: %v64 = alloca i1, i64 1, align 8 -; ALL: %v33 = alloca i1, i33 1, align 8 +; ALL: %v64 = alloca i1, align 8 +; ALL: %v33 = alloca i1, align 8 %v32 = alloca i1, align 8 %v64 = alloca i1, i64 1, align 8 %v33 = alloca i1, i33 1, align 8 |

