[llvm] r267689 - Use DL preferred alignment for alloca in Value::getPointerAlignment
Artur Pilipenko via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 27 03:42:29 PDT 2016
Author: apilipenko
Date: Wed Apr 27 05:42:29 2016
New Revision: 267689
URL: http://llvm.org/viewvc/llvm-project?rev=267689&view=rev
Log:
Use DL preferred alignment for alloca in Value::getPointerAlignment
Teach Value::getPointerAlignment that allocas with no explicit alignment are aligned to preferred alignment of the allocated type.
Reviewed By: hfinkel
Differential Revision: http://reviews.llvm.org/D17569
Modified:
llvm/trunk/lib/IR/Value.cpp
llvm/trunk/test/Analysis/ValueTracking/memory-dereferenceable.ll
Modified: llvm/trunk/lib/IR/Value.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Value.cpp?rev=267689&r1=267688&r2=267689&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Value.cpp (original)
+++ llvm/trunk/lib/IR/Value.cpp Wed Apr 27 05:42:29 2016
@@ -554,9 +554,14 @@ unsigned Value::getPointerAlignment(cons
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)) {
Modified: llvm/trunk/test/Analysis/ValueTracking/memory-dereferenceable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ValueTracking/memory-dereferenceable.ll?rev=267689&r1=267688&r2=267689&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/ValueTracking/memory-dereferenceable.ll (original)
+++ llvm/trunk/test/Analysis/ValueTracking/memory-dereferenceable.ll Wed Apr 27 05:42:29 2016
@@ -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
}
More information about the llvm-commits
mailing list