OLD | NEW |
---|---|
(Empty) | |
1 ; RUN: opt %s -normalize-struct-reg-signatures -S | FileCheck %s | |
2 | |
3 %struct = type { i32, i32 } | |
4 %rec_struct = type {%rec_struct*} | |
5 %rec_problem_struct = type{void (%rec_problem_struct)*} | |
6 %rec_pair_1 = type {%rec_pair_2*} | |
7 %rec_pair_2 = type {%rec_pair_1*} | |
8 | |
9 ; externs | |
10 declare void @extern_func(%struct) | |
11 declare %struct @struct_returning_extern(i32, %struct) | |
12 | |
13 define void @main(%struct* byval %ptr) { | |
JF
2015/03/08 22:04:38
Could you move the CHECK next to each function? It
| |
14 %val = load %struct* %ptr | |
15 call void @extern_func(%struct %val) | |
16 ret void | |
17 } | |
18 | |
19 define void @two_param_func(%struct %val1, %struct %val2) { | |
20 call void @extern_func(%struct %val1) | |
21 call void @extern_func(%struct %val2) | |
22 ret void | |
23 } | |
24 | |
25 define i32 @another_func(i32 %a, %struct %str, i64 %b) { | |
26 call void @two_param_func(%struct %str, %struct %str) | |
27 call void @extern_func(%struct %str) | |
28 ret i32 0 | |
29 } | |
30 | |
31 define %struct @returns_struct(i32 %an_int, %struct %val) { | |
32 %tmp = call %struct @struct_returning_extern(i32 %an_int, %struct %val) | |
33 ret %struct %tmp | |
34 } | |
35 | |
36 define i32 @lots_of_call_attrs() { | |
37 %tmp.0 = insertvalue %struct undef, i32 1, 0 | |
38 %tmp.1 = insertvalue %struct %tmp.0, i32 2, 1 | |
39 %ret = tail call zeroext i32 @another_func(i32 1, %struct %tmp.1, i64 2) reado nly | |
40 ret i32 %ret | |
41 } | |
42 | |
43 declare void @rec_struct_ok(%rec_struct*) | |
44 declare void @rec_struct_mod(%rec_struct) | |
45 | |
46 define void @rec_call_sreg(%rec_problem_struct %r) { | |
47 %tmp = extractvalue %rec_problem_struct %r, 0 | |
48 call void %tmp(%rec_problem_struct %r) | |
49 ret void | |
50 } | |
51 | |
52 declare void @pairs(%rec_pair_1) | |
53 | |
54 %rec_returning = type { %rec_returning (%rec_returning)* } | |
55 | |
56 define %rec_returning @rec_returning_fun(%rec_returning %str) { | |
57 %tmp = extractvalue %rec_returning %str, 0 | |
58 %ret = call %rec_returning %tmp(%rec_returning %str) | |
59 ret %rec_returning %ret | |
60 } | |
61 | |
62 ; verify that parameters are mapped correctly: single param, two, and combo | |
63 ; with non-struct regs | |
64 ; CHECK-NOT: declare void @extern_func(%struct) | |
65 ; CHECK-NOT: declare %struct @struct_returning_extern(i32, %struct) | |
66 ; CHECK: declare void @extern_func(%struct* byval) | |
67 ; CHECK: declare void @struct_returning_extern(%struct* sret, i32, %struct* byva l) | |
68 | |
69 ; CHECK: define void @two_param_func(%struct* byval %val1.ptr, %struct* byval %v al2.ptr) | |
70 ; CHECK-NOT: define void @two_param_func(%struct %val1, %struct %val2) | |
71 | |
72 ; CHECK: define i32 @another_func(i32 %a, %struct* byval %str.ptr, i64 %b) | |
73 ; CHECK: call void @two_param_func(%struct* byval %str.sreg.ptr1, %struct* byval %str.sreg.ptr2) | |
74 | |
75 ; verify return value and codegen | |
76 ; CHECK: define void @returns_struct(%struct* sret %retVal, i32 %an_int, %struct * byval %val.ptr) | |
77 ; CHECK-NEXT: %val.sreg = load %struct* %val.ptr | |
78 ; CHECK-NEXT: %1 = alloca %struct | |
79 ; CHECK-NEXT: %val.sreg.ptr = alloca %struct | |
80 ; CHECK-NEXT: store %struct %val.sreg, %struct* %val.sreg.ptr | |
81 ; CHECK-NEXT: call void @struct_returning_extern(%struct* sret %1, i32 %an_int, %struct* byval %val.sreg.ptr) | |
82 ; CHECK-NEXT: %tmp.sreg = load %struct* %1 | |
83 ; CHECK-NEXT: store %struct %tmp.sreg, %struct* %retVal | |
84 ; CHECK-NEXT: ret void | |
85 | |
86 ; verify attributes are copied | |
87 ; CHECK: %1 = tail call zeroext i32 @another_func(i32 1, %struct* byval %tmp.1.p tr, i64 2) #0 | |
88 ; CHECK-NEXT: ret i32 %1 | |
89 | |
90 ; compliant recursive structs are kept as-is | |
91 ; CHECK: declare void @rec_struct_ok(%rec_struct*) | |
92 ; CHECK: declare void @rec_struct_mod(%rec_struct* byval) | |
93 | |
94 ; non-compliant structs are correctly mapped and calls are changed | |
95 ; CHECK: define void @rec_call_sreg(%rec_problem_struct.2* byval %r.ptr) | |
96 ; CHECK: call void %tmp(%rec_problem_struct.2* byval %r.sreg.ptr) | |
97 | |
98 ; pair structs | |
99 ; CHECK: declare void @pairs(%rec_pair_1* byval) | |
100 ; CHECK: define void @rec_returning_fun(%rec_returning.6* sret %retVal, %rec_ret urning.6* byval %str.ptr) | |
101 ; CHECK-NEXT: %str.sreg = load %rec_returning.6* %str.ptr | |
102 ; CHECK-NEXT: %tmp = extractvalue %rec_returning.6 %str.sreg, 0 | |
103 ; CHECK-NEXT: %1 = alloca %rec_returning.6 | |
104 ; CHECK-NEXT: %str.sreg.ptr = alloca %rec_returning.6 | |
105 ; CHECK-NEXT: store %rec_returning.6 %str.sreg, %rec_returning.6* %str.sreg.pt r | |
106 ; CHECK-NEXT: call void %tmp(%rec_returning.6* sret %1, %rec_returning.6* byva l %str.sreg.ptr) | |
107 ; CHECK-NEXT: %ret.sreg = load %rec_returning.6* %1 | |
108 ; CHECK-NEXT: store %rec_returning.6 %ret.sreg, %rec_returning.6* %retVal | |
109 ; CHECK-NEXT: ret void | |
110 | |
111 ; this is at the end, corresponds to the call marked as readonly | |
112 ; CHECK: attributes #0 = { readonly } | |
OLD | NEW |