mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
Teach DataLayout to infer a plausible alignment for things even when nothing is specified by the user.
llvm-svn: 231613
This commit is contained in:
parent
171a02e1ca
commit
e54101bbb5
@ -479,9 +479,7 @@ unsigned DataLayout::getAlignmentInfo(AlignTypeEnum AlignType,
|
||||
// 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(AlignTypeEnum AlignType,
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
10
test/Transforms/InstCombine/default-alignment.ll
Normal file
10
test/Transforms/InstCombine/default-alignment.ll
Normal file
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user