llvm.org GIT mirror llvm / c7429cb
[ArgPromotion] Preserve alignment of byval argument in new alloca The frontend may have requested a higher alignment for any reason, and downstream optimizations may already have taken advantage of it. We should keep the same alignment when moving the allocation from the parameter area to the local variable area. Fixes PR34038 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310071 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 2 years ago
2 changed file(s) with 32 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
355355 // Just add all the struct element types.
356356 Type *AgTy = cast(I->getType())->getElementType();
357357 Value *TheAlloca = new AllocaInst(AgTy, DL.getAllocaAddrSpace(), nullptr,
358 "", InsertPt);
358 I->getParamAlignment(), "", InsertPt);
359359 StructType *STy = cast(AgTy);
360360 Value *Idxs[2] = {ConstantInt::get(Type::getInt32Ty(F->getContext()), 0),
361361 nullptr};
55 %struct.ss = type { i32, i64 }
66
77 define internal void @f(%struct.ss* byval %b) nounwind {
8 ; CHECK-LABEL: define internal void @f(i32 %b.0, i64 %b.1)
98 entry:
10 %tmp = getelementptr %struct.ss, %struct.ss* %b, i32 0, i32 0 ; [#uses=2]
11 %tmp1 = load i32, i32* %tmp, align 4 ; [#uses=1]
12 %tmp2 = add i32 %tmp1, 1 ; [#uses=1]
9 %tmp = getelementptr %struct.ss, %struct.ss* %b, i32 0, i32 0
10 %tmp1 = load i32, i32* %tmp, align 4
11 %tmp2 = add i32 %tmp1, 1
1312 store i32 %tmp2, i32* %tmp, align 4
1413 ret void
1514 }
1615
16 ; CHECK-LABEL: define internal void @f(i32 %b.0, i64 %b.1)
17 ; CHECK: alloca %struct.ss{{$}}
18 ; CHECK: store i32 %b.0
19 ; CHECK: store i64 %b.1
20
21 define internal void @g(%struct.ss* byval align 32 %b) nounwind {
22 entry:
23 %tmp = getelementptr %struct.ss, %struct.ss* %b, i32 0, i32 0
24 %tmp1 = load i32, i32* %tmp, align 4
25 %tmp2 = add i32 %tmp1, 1
26 store i32 %tmp2, i32* %tmp, align 4
27 ret void
28 }
29
30 ; CHECK-LABEL: define internal void @g(i32 %b.0, i64 %b.1)
31 ; CHECK: alloca %struct.ss, align 32
32 ; CHECK: store i32 %b.0
33 ; CHECK: store i64 %b.1
34
1735 define i32 @main() nounwind {
18 ; CHECK-LABEL: define i32 @main
1936 entry:
20 %S = alloca %struct.ss ; <%struct.ss*> [#uses=4]
21 %tmp1 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 0 ; [#uses=1]
37 %S = alloca %struct.ss
38 %tmp1 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 0
2239 store i32 1, i32* %tmp1, align 8
23 %tmp4 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 1 ; [#uses=1]
40 %tmp4 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 1
2441 store i64 2, i64* %tmp4, align 4
25 call void @f( %struct.ss* byval %S ) nounwind
26 ; CHECK: call void @f(i32 %{{.*}}, i64 %{{.*}})
42 call void @f(%struct.ss* byval %S) nounwind
43 call void @g(%struct.ss* byval %S) nounwind
2744 ret i32 0
2845 }
46
47 ; CHECK-LABEL: define i32 @main
48 ; CHECK: call void @f(i32 %{{.*}}, i64 %{{.*}})
49 ; CHECK: call void @g(i32 %{{.*}}, i64 %{{.*}})