[llvm] r232202 - instcombine: alloca: Canonicalize scalar allocation array size

Duncan P. N. Exon Smith dexonsmith at apple.com
Fri Mar 13 12:42:10 PDT 2015


Author: dexonsmith
Date: Fri Mar 13 14:42:09 2015
New Revision: 232202

URL: http://llvm.org/viewvc/llvm-project?rev=232202&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
    llvm/trunk/test/Transforms/InstCombine/alloca.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=232202&r1=232201&r2=232202&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp Fri Mar 13 14:42:09 2015
@@ -166,8 +166,16 @@ isOnlyCopiedFromConstantGlobal(AllocaIns
 
 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())) {

Modified: llvm/trunk/test/Transforms/InstCombine/alloca.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/alloca.ll?rev=232202&r1=232201&r2=232202&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/alloca.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/alloca.ll Fri Mar 13 14:42:09 2015
@@ -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





More information about the llvm-commits mailing list