[llvm] r231613 - Teach DataLayout to infer a plausible alignment for things even when nothing is specified by the user.
Owen Anderson
resistor at mac.com
Sun Mar 8 14:53:59 PDT 2015
Author: resistor
Date: Sun Mar 8 16:53:59 2015
New Revision: 231613
URL: http://llvm.org/viewvc/llvm-project?rev=231613&view=rev
Log:
Teach DataLayout to infer a plausible alignment for things even when nothing is specified by the user.
Added:
llvm/trunk/test/Transforms/InstCombine/default-alignment.ll
Modified:
llvm/trunk/lib/IR/DataLayout.cpp
Modified: llvm/trunk/lib/IR/DataLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DataLayout.cpp?rev=231613&r1=231612&r2=231613&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DataLayout.cpp (original)
+++ llvm/trunk/lib/IR/DataLayout.cpp Sun Mar 8 16:53:59 2015
@@ -479,9 +479,7 @@ unsigned DataLayout::getAlignmentInfo(Al
// If we didn't find an integer alignment, fall back on most conservative.
if (AlignType == INTEGER_ALIGN) {
BestMatchIdx = LargestInt;
- } else {
- assert(AlignType == VECTOR_ALIGN && "Unknown alignment type!");
-
+ } else if (AlignType == VECTOR_ALIGN) {
// By default, use natural alignment for vector types. This is consistent
// with what clang and llvm-gcc do.
unsigned Align = getTypeAllocSize(cast<VectorType>(Ty)->getElementType());
@@ -494,6 +492,19 @@ unsigned DataLayout::getAlignmentInfo(Al
}
}
+ // If we still couldn't find a reasonable default alignment, fall back
+ // to a simple heuristic that the alignment is the first power of two
+ // greater-or-equal to the store size of the type. This is a reasonable
+ // approximation of reality, and if the user wanted something less
+ // less conservative, they should have specified it explicitly in the data
+ // layout.
+ if (BestMatchIdx == -1) {
+ unsigned Align = getTypeStoreSize(Ty);
+ if (Align & (Align-1))
+ Align = NextPowerOf2(Align);
+ return Align;
+ }
+
// Since we got a "best match" index, just return it.
return ABIInfo ? Alignments[BestMatchIdx].ABIAlign
: Alignments[BestMatchIdx].PrefAlign;
Added: llvm/trunk/test/Transforms/InstCombine/default-alignment.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/default-alignment.ll?rev=231613&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/default-alignment.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/default-alignment.ll Sun Mar 8 16:53:59 2015
@@ -0,0 +1,10 @@
+; RUN: opt -verify -instcombine < %s
+%Foo = type <{ i8, x86_fp80 }>
+
+define i8 @t(%Foo* %arg) {
+entry:
+ %0 = getelementptr %Foo, %Foo* %arg, i32 0, i32 0
+ %1 = load i8, i8* %0, align 1
+ ret i8 %1
+}
+
More information about the llvm-commits
mailing list