1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
2 ; RUN: opt < %s -passes=argpromotion -S | FileCheck %s
5 ; Don't promote arguments of musttail callee
7 %T = type { i32, i32, i32, i32 }
9 define internal i32 @test(%T* %p) {
10 ; CHECK-LABEL: define {{[^@]+}}@test
11 ; CHECK-SAME: (%T* [[P:%.*]])
12 ; CHECK-NEXT: [[A_GEP:%.*]] = getelementptr [[T:%.*]], %T* [[P]], i64 0, i32 3
13 ; CHECK-NEXT: [[B_GEP:%.*]] = getelementptr [[T]], %T* [[P]], i64 0, i32 2
14 ; CHECK-NEXT: [[A:%.*]] = load i32, i32* [[A_GEP]]
15 ; CHECK-NEXT: [[B:%.*]] = load i32, i32* [[B_GEP]]
16 ; CHECK-NEXT: [[V:%.*]] = add i32 [[A]], [[B]]
17 ; CHECK-NEXT: ret i32 [[V]]
19 %a.gep = getelementptr %T, %T* %p, i64 0, i32 3
20 %b.gep = getelementptr %T, %T* %p, i64 0, i32 2
21 %a = load i32, i32* %a.gep
22 %b = load i32, i32* %b.gep
27 define i32 @caller(%T* %p) {
28 ; CHECK-LABEL: define {{[^@]+}}@caller
29 ; CHECK-SAME: (%T* [[P:%.*]])
30 ; CHECK-NEXT: [[V:%.*]] = musttail call i32 @test(%T* [[P]])
31 ; CHECK-NEXT: ret i32 [[V]]
33 %v = musttail call i32 @test(%T* %p)
37 ; Don't promote arguments of musttail caller
39 define i32 @foo(%T* %p, i32 %v) {
40 ; CHECK-LABEL: define {{[^@]+}}@foo
41 ; CHECK-SAME: (%T* [[P:%.*]], i32 [[V:%.*]])
42 ; CHECK-NEXT: ret i32 0
47 define internal i32 @test2(%T* %p, i32 %p2) {
48 ; CHECK-LABEL: define {{[^@]+}}@test2
49 ; CHECK-SAME: (%T* [[P:%.*]], i32 [[P2:%.*]])
50 ; CHECK-NEXT: [[A_GEP:%.*]] = getelementptr [[T:%.*]], %T* [[P]], i64 0, i32 3
51 ; CHECK-NEXT: [[B_GEP:%.*]] = getelementptr [[T]], %T* [[P]], i64 0, i32 2
52 ; CHECK-NEXT: [[A:%.*]] = load i32, i32* [[A_GEP]]
53 ; CHECK-NEXT: [[B:%.*]] = load i32, i32* [[B_GEP]]
54 ; CHECK-NEXT: [[V:%.*]] = add i32 [[A]], [[B]]
55 ; CHECK-NEXT: [[CA:%.*]] = musttail call i32 @foo(%T* undef, i32 [[V]])
56 ; CHECK-NEXT: ret i32 [[CA]]
58 %a.gep = getelementptr %T, %T* %p, i64 0, i32 3
59 %b.gep = getelementptr %T, %T* %p, i64 0, i32 2
60 %a = load i32, i32* %a.gep
61 %b = load i32, i32* %b.gep
63 %ca = musttail call i32 @foo(%T* undef, i32 %v)
67 define i32 @caller2(%T* %g) {
68 ; CHECK-LABEL: define {{[^@]+}}@caller2
69 ; CHECK-SAME: (%T* [[G:%.*]])
70 ; CHECK-NEXT: [[V:%.*]] = call i32 @test2(%T* [[G]], i32 0)
71 ; CHECK-NEXT: ret i32 [[V]]
73 %v = call i32 @test2(%T* %g, i32 0)