[llvm-commits] [llvm] r164117 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp test/Transforms/InstCombine/2012-09-17-ZeroSizedAlloca.ll
Richard Osborne
richard at xmos.com
Tue Sep 18 02:31:45 PDT 2012
Author: friedgold
Date: Tue Sep 18 04:31:44 2012
New Revision: 164117
URL: http://llvm.org/viewvc/llvm-project?rev=164117&view=rev
Log:
Fix instcombine to obey requested alignment when merging allocas.
Added:
llvm/trunk/test/Transforms/InstCombine/2012-09-17-ZeroSizedAlloca.ll
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=164117&r1=164116&r2=164117&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp Tue Sep 18 04:31:44 2012
@@ -246,12 +246,16 @@
return &AI;
}
+ // If the alignment of the entry block alloca is 0 (unspecified),
+ // assign it the preferred alignment.
+ if (EntryAI->getAlignment() == 0)
+ EntryAI->setAlignment(
+ TD->getPrefTypeAlignment(EntryAI->getAllocatedType()));
// Replace this zero-sized alloca with the one at the start of the entry
// block after ensuring that the address will be aligned enough for both
// types.
- unsigned MaxAlign =
- std::max(TD->getPrefTypeAlignment(EntryAI->getAllocatedType()),
- TD->getPrefTypeAlignment(AI.getAllocatedType()));
+ unsigned MaxAlign = std::max(EntryAI->getAlignment(),
+ AI.getAlignment());
EntryAI->setAlignment(MaxAlign);
if (AI.getType() != EntryAI->getType())
return new BitCastInst(EntryAI, AI.getType());
Added: llvm/trunk/test/Transforms/InstCombine/2012-09-17-ZeroSizedAlloca.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2012-09-17-ZeroSizedAlloca.ll?rev=164117&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2012-09-17-ZeroSizedAlloca.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/2012-09-17-ZeroSizedAlloca.ll Tue Sep 18 04:31:44 2012
@@ -0,0 +1,24 @@
+; RUN: opt -S -instcombine < %s | FileCheck %s
+
+; When merging zero sized alloca check that requested alignments of the allocas
+; are obeyed.
+
+ at x = global i8* null, align 8
+ at y = global i8* null, align 8
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.8.0"
+
+; CHECK: @f
+; CHECK-NEXT: alloca [0 x i8], align 1024
+; CHECK-NOT: alloca
+; CHECK: ret void
+define void @f() {
+ %1 = alloca [0 x i8], align 1
+ %2 = alloca [0 x i8], align 1024
+ %3 = getelementptr inbounds [0 x i8]* %1, i64 0, i64 0
+ %4 = getelementptr inbounds [0 x i8]* %2, i64 0, i64 0
+ store i8* %3, i8** @x, align 8
+ store i8* %4, i8** @y, align 8
+ ret void
+}
More information about the llvm-commits
mailing list