diff options
| author | Dan Gohman <gohman@apple.com> | 2009-01-13 20:18:38 +0000 |
|---|---|---|
| committer | Dan Gohman <gohman@apple.com> | 2009-01-13 20:18:38 +0000 |
| commit | 59af77376c099516c7a54118dd69183658755371 (patch) | |
| tree | 31d5daefda3c19a44f942c76c22d798a102c1c06 /llvm/lib | |
| parent | 89100920d63faf9e6d73dba0116721c4ac20e825 (diff) | |
| download | bcm5719-llvm-59af77376c099516c7a54118dd69183658755371.tar.gz bcm5719-llvm-59af77376c099516c7a54118dd69183658755371.zip | |
Make instcombine ensure that all allocas are explicitly aligned at at
least their preferred alignment.
llvm-svn: 62176
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index ee3596bde43..f640915386d 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/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; } |

