tailcall-extract.ll
5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
; RUN: llc -mtriple=x86_64-linux < %s | FileCheck %s
; RUN: opt -codegenprepare -S -mtriple=x86_64-linux < %s | FileCheck %s --check-prefix OPT
; The exit block containing extractvalue can be duplicated into the BB
; containing call. And later tail call can be generated.
; CHECK-LABEL: test1:
; CHECK: jmp bar # TAILCALL
; CHECK: jmp foo # TAILCALL
; OPT-LABEL: test1
; OPT: if.then.i:
; OPT-NEXT: tail call { i8*, i64 } @bar
; OPT-NEXT: extractvalue
; OPT-NEXT: bitcast
; OPT-NEXT: ret
;
; OPT: if.end.i:
; OPT-NEXT: tail call { i8*, i64 } @foo
; OPT-NEXT: extractvalue
; OPT-NEXT: bitcast
; OPT-NEXT: ret
define i64* @test1(i64 %size) {
entry:
%cmp.i.i = icmp ugt i64 %size, 16384
%add.i.i = add i64 %size, 7
%div.i.i = lshr i64 %add.i.i, 3
%phitmp.i.i = trunc i64 %div.i.i to i32
%cmp1.i = icmp eq i32 %phitmp.i.i, 0
%cmp.i = or i1 %cmp.i.i, %cmp1.i
br i1 %cmp.i, label %if.end.i, label %if.then.i
if.then.i: ; preds = %entry
%call1.i = tail call { i8*, i64 } @bar(i64 %size)
br label %exit
if.end.i: ; preds = %entry
%call2.i = tail call { i8*, i64 } @foo(i64 %size)
br label %exit
exit:
%call1.i.sink = phi { i8*, i64 } [ %call1.i, %if.then.i ], [ %call2.i, %if.end.i ]
%ev = extractvalue { i8*, i64 } %call1.i.sink, 0
%result = bitcast i8* %ev to i64*
ret i64* %result
}
; The extractvalue extracts a field with non-zero offset, so the exit block
; can't be duplicated.
; CHECK-LABEL: test2:
; CHECK: callq bar
; CHECK: callq foo
; OPT-LABEL: test2
; OPT: if.then.i:
; OPT-NEXT: tail call { i8*, i64 } @bar
; OPT-NEXT: br label %exit
;
; OPT: if.end.i:
; OPT-NEXT: tail call { i8*, i64 } @foo
; OPT-NEXT: br label %exit
;
; OPT: exit:
; OPT-NEXT: phi
; OPT-NEXT: extractvalue
; OPT-NEXT: ret
define i64 @test2(i64 %size) {
entry:
%cmp.i.i = icmp ugt i64 %size, 16384
%add.i.i = add i64 %size, 7
%div.i.i = lshr i64 %add.i.i, 3
%phitmp.i.i = trunc i64 %div.i.i to i32
%cmp1.i = icmp eq i32 %phitmp.i.i, 0
%cmp.i = or i1 %cmp.i.i, %cmp1.i
br i1 %cmp.i, label %if.end.i, label %if.then.i
if.then.i: ; preds = %entry
%call1.i = tail call { i8*, i64 } @bar(i64 %size)
br label %exit
if.end.i: ; preds = %entry
%call2.i = tail call { i8*, i64 } @foo(i64 %size)
br label %exit
exit:
%call1.i.sink = phi { i8*, i64 } [ %call1.i, %if.then.i ], [ %call2.i, %if.end.i ]
%ev = extractvalue { i8*, i64 } %call1.i.sink, 1
ret i64 %ev
}
; The extractvalue accesses a nest struct type, the extracted field has zero
; offset, so the exit block can still be duplicated, and tail call generated.
; CHECK-LABEL: test3:
; CHECK: jmp baz # TAILCALL
; CHECK: jmp qux # TAILCALL
; OPT-LABEL: test3
; OPT: if.then.i:
; OPT-NEXT: tail call { { i8*, i64 }, i64 } @baz
; OPT-NEXT: extractvalue
; OPT-NEXT: bitcast
; OPT-NEXT: ret
;
; OPT: if.end.i:
; OPT-NEXT: tail call { { i8*, i64 }, i64 } @qux
; OPT-NEXT: extractvalue
; OPT-NEXT: bitcast
; OPT-NEXT: ret
define i64* @test3(i64 %size) {
entry:
%cmp.i.i = icmp ugt i64 %size, 16384
%add.i.i = add i64 %size, 7
%div.i.i = lshr i64 %add.i.i, 3
%phitmp.i.i = trunc i64 %div.i.i to i32
%cmp1.i = icmp eq i32 %phitmp.i.i, 0
%cmp.i = or i1 %cmp.i.i, %cmp1.i
br i1 %cmp.i, label %if.end.i, label %if.then.i
if.then.i: ; preds = %entry
%call1.i = tail call { {i8*, i64}, i64 } @baz(i64 %size)
br label %exit
if.end.i: ; preds = %entry
%call2.i = tail call { {i8*, i64}, i64 } @qux(i64 %size)
br label %exit
exit:
%call1.i.sink = phi { {i8*, i64}, i64 } [ %call1.i, %if.then.i ], [ %call2.i, %if.end.i ]
%ev = extractvalue { {i8*, i64}, i64 } %call1.i.sink, 0, 0
%result = bitcast i8* %ev to i64*
ret i64* %result
}
; The extractvalue accesses a nest struct with non-zero offset, so the exit
; block can't be duplicated.
; CHECK-LABEL: test4:
; CHECK: callq baz
; CHECK: callq qux
; OPT-LABEL: test4
; OPT: if.then.i:
; OPT-NEXT: tail call { { i8*, i64 }, i64 } @baz
; OPT-NEXT: br label %exit
;
; OPT: if.end.i:
; OPT-NEXT: tail call { { i8*, i64 }, i64 } @qux
; OPT-NEXT: br label %exit
;
; OPT: exit:
; OPT-NEXT: phi
; OPT-NEXT: extractvalue
; OPT-NEXT: ret
define i64 @test4(i64 %size) {
entry:
%cmp.i.i = icmp ugt i64 %size, 16384
%add.i.i = add i64 %size, 7
%div.i.i = lshr i64 %add.i.i, 3
%phitmp.i.i = trunc i64 %div.i.i to i32
%cmp1.i = icmp eq i32 %phitmp.i.i, 0
%cmp.i = or i1 %cmp.i.i, %cmp1.i
br i1 %cmp.i, label %if.end.i, label %if.then.i
if.then.i: ; preds = %entry
%call1.i = tail call { {i8*, i64}, i64 } @baz(i64 %size)
br label %exit
if.end.i: ; preds = %entry
%call2.i = tail call { {i8*, i64}, i64 } @qux(i64 %size)
br label %exit
exit:
%call1.i.sink = phi { {i8*, i64}, i64 } [ %call1.i, %if.then.i ], [ %call2.i, %if.end.i ]
%ev = extractvalue { {i8*, i64}, i64 } %call1.i.sink, 0, 1
ret i64 %ev
}
declare { i8*, i64 } @foo(i64)
declare { i8*, i64 } @bar(i64)
declare { {i8*, i64}, i64 } @baz(i64)
declare { {i8*, i64}, i64 } @qux(i64)