aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-01-13 20:18:38 +0000
committerDan Gohman <gohman@apple.com>2009-01-13 20:18:38 +0000
commit28e78f033533058f1834cba526de20b46ff58894 (patch)
tree7f565f242173d6387ffe674d2384b309a816cf14 /lib
parent4affaeabfdf2f62de08666f203f24bb9491b2b9c (diff)
downloadexternal_llvm-28e78f033533058f1834cba526de20b46ff58894.zip
external_llvm-28e78f033533058f1834cba526de20b46ff58894.tar.gz
external_llvm-28e78f033533058f1834cba526de20b46ff58894.tar.bz2
Make instcombine ensure that all allocas are explicitly aligned at at
least their preferred alignment. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62176 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index ee3596b..f640915 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -10775,12 +10775,17 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) {
}
}
- // 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;
}