Recommit r158407: Allow SROA to look at a vector type and see if the offset is out of range to be replaced with a scalar access. Now with additional fix and test for indexing into a vector inside a struct

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158454 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Pete Cooper 2012-06-14 16:38:13 +00:00
parent b5a1bf4780
commit 77fdd3ad4a
2 changed files with 33 additions and 9 deletions

View File

@ -1764,6 +1764,12 @@ bool SROA::TypeHasComponent(Type *T, uint64_t Offset, uint64_t Size) {
if (Offset >= AT->getNumElements() * EltSize) if (Offset >= AT->getNumElements() * EltSize)
return false; return false;
Offset %= EltSize; Offset %= EltSize;
} else if (VectorType *VT = dyn_cast<VectorType>(T)) {
EltTy = VT->getElementType();
EltSize = TD->getTypeAllocSize(EltTy);
if (Offset >= VT->getNumElements() * EltSize)
return false;
Offset %= EltSize;
} else { } else {
return false; return false;
} }
@ -1931,9 +1937,16 @@ uint64_t SROA::FindElementAndOffset(Type *&T, uint64_t &Offset,
Offset -= Layout->getElementOffset(Idx); Offset -= Layout->getElementOffset(Idx);
IdxTy = Type::getInt32Ty(T->getContext()); IdxTy = Type::getInt32Ty(T->getContext());
return Idx; return Idx;
} else if (ArrayType *AT = dyn_cast<ArrayType>(T)) {
T = AT->getElementType();
uint64_t EltSize = TD->getTypeAllocSize(T);
Idx = Offset / EltSize;
Offset -= Idx * EltSize;
IdxTy = Type::getInt64Ty(T->getContext());
return Idx;
} }
ArrayType *AT = cast<ArrayType>(T); VectorType *VT = cast<VectorType>(T);
T = AT->getElementType(); T = VT->getElementType();
uint64_t EltSize = TD->getTypeAllocSize(T); uint64_t EltSize = TD->getTypeAllocSize(T);
Idx = Offset / EltSize; Idx = Offset / EltSize;
Offset -= Idx * EltSize; Offset -= Idx * EltSize;

View File

@ -10,8 +10,7 @@ target triple = "x86_64-apple-macosx10.7.0"
; CHECK: main ; CHECK: main
; CHECK-NOT: alloca ; CHECK-NOT: alloca
; CHECK: %[[A:[a-z0-9]*]] = and i128 ; CHECK: extractelement <2 x float> zeroinitializer, i32 0
; CHECK: %[[B:[a-z0-9]*]] = trunc i128 %[[A]] to i32
define void @main() uwtable ssp { define void @main() uwtable ssp {
entry: entry:
@ -28,8 +27,7 @@ entry:
; CHECK: test1 ; CHECK: test1
; CHECK-NOT: alloca ; CHECK-NOT: alloca
; CHECK: %[[A:[a-z0-9]*]] = and i128 ; CHECK: extractelement <2 x float> zeroinitializer, i32 0
; CHECK: %[[B:[a-z0-9]*]] = trunc i128 %[[A]] to i32
define void @test1() uwtable ssp { define void @test1() uwtable ssp {
entry: entry:
@ -43,9 +41,8 @@ entry:
; CHECK: test2 ; CHECK: test2
; CHECK-NOT: alloca ; CHECK-NOT: alloca
; CHECK: and i128 ; CHECK: %[[A:[a-z0-9]*]] = extractelement <2 x float> zeroinitializer, i32 0
; CHECK: or i128 ; CHECK: fadd float %[[A]], 1.000000e+00
; CHECK: trunc i128
; CHECK-NOT: insertelement ; CHECK-NOT: insertelement
; CHECK-NOT: extractelement ; CHECK-NOT: extractelement
@ -62,3 +59,17 @@ entry:
%r = fadd float %r1, %r2 %r = fadd float %r1, %r2
ret float %r ret float %r
} }
; CHECK: test3
; CHECK: %[[A:[a-z0-9]*]] = extractelement <2 x float> <float 2.000000e+00, float 3.000000e+00>, i32 1
; CHECK: ret float %[[A]]
define float @test3() {
entry:
%ai = alloca { <2 x float>, <2 x float> }, align 8
store { <2 x float>, <2 x float> } {<2 x float> <float 0.0, float 1.0>, <2 x float> <float 2.0, float 3.0>}, { <2 x float>, <2 x float> }* %ai, align 8
%tmpcast = bitcast { <2 x float>, <2 x float> }* %ai to [4 x float]*
%arrayidx = getelementptr inbounds [4 x float]* %tmpcast, i64 0, i64 3
%f = load float* %arrayidx, align 4
ret float %f
}