• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
2; RUN: opt < %s -argpromotion -S | FileCheck %s
3; PR36543
4
5; Don't promote arguments of musttail callee
6
7%T = type { i32, i32, i32, i32 }
8
9define 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]]
18;
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
23  %v = add i32 %a, %b
24  ret i32 %v
25}
26
27define 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]]
32;
33  %v = musttail call i32 @test(%T* %p)
34  ret i32 %v
35}
36
37; Don't promote arguments of musttail caller
38
39define i32 @foo(%T* %p, i32 %v) {
40; CHECK-LABEL: define {{[^@]+}}@foo
41; CHECK-SAME: (%T* [[P:%.*]], i32 [[V:%.*]])
42; CHECK-NEXT:    ret i32 0
43;
44  ret i32 0
45}
46
47define 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]]
57;
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
62  %v = add i32 %a, %b
63  %ca = musttail call i32 @foo(%T* undef, i32 %v)
64  ret i32 %ca
65}
66
67define 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]]
72;
73  %v = call i32 @test2(%T* %g, i32 0)
74  ret i32 %v
75}
76