summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/IR/Value.cpp9
-rw-r--r--llvm/test/Analysis/ValueTracking/memory-dereferenceable.ll8
2 files changed, 14 insertions, 3 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index cc20c4855f2..08b4936e702 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -554,9 +554,14 @@ unsigned Value::getPointerAlignment(const DataLayout &DL) const {
if (EltTy->isSized())
Align = DL.getABITypeAlignment(EltTy);
}
- } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(this))
+ } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(this)) {
Align = AI->getAlignment();
- else if (auto CS = ImmutableCallSite(this))
+ if (Align == 0) {
+ Type *AllocatedType = AI->getAllocatedType();
+ if (AllocatedType->isSized())
+ Align = DL.getPrefTypeAlignment(AllocatedType);
+ }
+ } else if (auto CS = ImmutableCallSite(this))
Align = CS.getAttributes().getParamAlignment(AttributeSet::ReturnIndex);
else if (const LoadInst *LI = dyn_cast<LoadInst>(this))
if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
diff --git a/llvm/test/Analysis/ValueTracking/memory-dereferenceable.ll b/llvm/test/Analysis/ValueTracking/memory-dereferenceable.ll
index 5b45172f695..15a93328974 100644
--- a/llvm/test/Analysis/ValueTracking/memory-dereferenceable.ll
+++ b/llvm/test/Analysis/ValueTracking/memory-dereferenceable.ll
@@ -3,7 +3,7 @@
; Uses the print-deref (+ analyze to print) pass to run
; isDereferenceablePointer() on many load instruction operands
-target datalayout = "e"
+target datalayout = "e-i32:32:64"
%TypeOpaque = type opaque
@@ -133,6 +133,12 @@ entry:
%load26 = load i32, i32* %d4_unaligned_load, align 16
%load27 = load i32, i32* %d4_aligned_load, align 16
+ ; Alloca with no explicit alignment is aligned to preferred alignment of
+ ; the type (specified by datalayout string).
+; CHECK: %alloca.noalign{{.*}}(aligned)
+ %alloca.noalign = alloca i32
+ %load28 = load i32, i32* %alloca.noalign, align 8
+
ret void
}
OpenPOWER on IntegriCloud