summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-03-13 19:42:09 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-03-13 19:42:09 +0000
commitbe95b4afc6d073677858f0751b74ab8917f5ae34 (patch)
treed1d4f3314b3a340ee8339225369aecc70c3e5603 /llvm/lib
parent07ff9b03f6bf750e491cdde73f943a65f58f0d80 (diff)
downloadbcm5719-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/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp12
1 files changed, 10 insertions, 2 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())) {
OpenPOWER on IntegriCloud