[PATCH] D17569: Use DL preferred alignment for alloca in Value::getPointerAlignment
Artur Pilipenko via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 24 06:47:25 PST 2016
apilipenko created this revision.
apilipenko added a reviewer: hfinkel.
apilipenko added a subscriber: llvm-commits.
Teach Value::getPointerAlignment that allocas with no explicit alignment are aligned to preferred alignment of the allocated type.
http://reviews.llvm.org/D17569
Files:
lib/IR/Value.cpp
test/Analysis/ValueTracking/memory-dereferenceable.ll
Index: test/Analysis/ValueTracking/memory-dereferenceable.ll
===================================================================
--- test/Analysis/ValueTracking/memory-dereferenceable.ll
+++ 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 @@
%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
}
Index: lib/IR/Value.cpp
===================================================================
--- lib/IR/Value.cpp
+++ lib/IR/Value.cpp
@@ -548,9 +548,14 @@
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)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17569.48927.patch
Type: text/x-patch
Size: 1769 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160224/f6683a56/attachment.bin>
More information about the llvm-commits
mailing list