[llvm-commits] [llvm] r62176 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/2009-01-08-AlignAlloca.ll test/Transforms/InstCombine/loadstore-alignment.ll
Dan Gohman
gohman at apple.com
Tue Jan 13 12:18:38 PST 2009
Author: djg
Date: Tue Jan 13 14:18:38 2009
New Revision: 62176
URL: http://llvm.org/viewvc/llvm-project?rev=62176&view=rev
Log:
Make instcombine ensure that all allocas are explicitly aligned at at
least their preferred alignment.
Modified:
llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
llvm/trunk/test/Transforms/InstCombine/2009-01-08-AlignAlloca.ll
llvm/trunk/test/Transforms/InstCombine/loadstore-alignment.ll
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=62176&r1=62175&r2=62176&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Tue Jan 13 14:18:38 2009
@@ -10775,12 +10775,17 @@
}
}
- // If alloca'ing a zero byte object, replace the alloca with a null pointer.
- // Note that we only do this for alloca's, because malloc should allocate and
- // return a unique pointer, even for a zero byte allocation.
- if (isa<AllocaInst>(AI) && AI.getAllocatedType()->isSized() &&
- TD->getTypePaddedSize(AI.getAllocatedType()) == 0)
- return ReplaceInstUsesWith(AI, Constant::getNullValue(AI.getType()));
+ if (isa<AllocaInst>(AI) && AI.getAllocatedType()->isSized()) {
+ // If alloca'ing a zero byte object, replace the alloca with a null pointer.
+ // Note that we only do this for alloca's, because malloc should allocate and
+ // return a unique pointer, even for a zero byte allocation.
+ if (TD->getTypePaddedSize(AI.getAllocatedType()) == 0)
+ return ReplaceInstUsesWith(AI, Constant::getNullValue(AI.getType()));
+
+ // If the alignment is 0 (unspecified), assign it the preferred alignment.
+ if (AI.getAlignment() == 0)
+ AI.setAlignment(TD->getPrefTypeAlignment(AI.getAllocatedType()));
+ }
return 0;
}
Modified: llvm/trunk/test/Transforms/InstCombine/2009-01-08-AlignAlloca.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2009-01-08-AlignAlloca.ll?rev=62176&r1=62175&r2=62176&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2009-01-08-AlignAlloca.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/2009-01-08-AlignAlloca.ll Tue Jan 13 14:18:38 2009
@@ -1,4 +1,6 @@
-; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep {, align 4} | count 4
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis > %t
+; RUN: grep {, align 4} %t | count 3
+; RUN: grep {, align 8} %t | count 3
; rdar://6480438
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
target triple = "i386-apple-darwin9.6"
Modified: llvm/trunk/test/Transforms/InstCombine/loadstore-alignment.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/loadstore-alignment.ll?rev=62176&r1=62175&r2=62176&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/loadstore-alignment.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/loadstore-alignment.ll Tue Jan 13 14:18:38 2009
@@ -1,4 +1,4 @@
-; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep {, align 16} | count 12
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep {, align 16} | count 14
@x = external global <2 x i64>, align 16
@xx = external global [13 x <2 x i64>], align 16
More information about the llvm-commits
mailing list