File: basic.ll

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (246 lines) | stat: -rw-r--r-- 6,674 bytes parent folder | download | duplicates (12)
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
; RUN: opt < %s -passes=tailcallelim -verify-dom-info -S | FileCheck %s

declare void @noarg()
declare void @use(ptr)
declare void @use_nocapture(ptr nocapture)
declare void @use2_nocapture(ptr nocapture, ptr nocapture)

; Trivial case. Mark @noarg with tail call.
define void @test0() {
; CHECK: tail call void @noarg()
	call void @noarg()
	ret void
}

; Make sure that we do not do TRE if pointer to local stack
; escapes through function call.
define i32 @test1() {
; CHECK: i32 @test1()
; CHECK-NEXT: alloca
	%A = alloca i32		; <ptr> [#uses=2]
	store i32 5, ptr %A
	call void @use(ptr %A)
; CHECK: call i32 @test1
	%X = call i32 @test1()		; <i32> [#uses=1]
	ret i32 %X
}

; This function contains intervening instructions which should be moved out of the way
define i32 @test2(i32 %X) {
; CHECK: i32 @test2
; CHECK-NOT: call
; CHECK: ret i32
entry:
	%tmp.1 = icmp eq i32 %X, 0		; <i1> [#uses=1]
	br i1 %tmp.1, label %then.0, label %endif.0
then.0:		; preds = %entry
	%tmp.4 = add i32 %X, 1		; <i32> [#uses=1]
	ret i32 %tmp.4
endif.0:		; preds = %entry
	%tmp.10 = add i32 %X, -1		; <i32> [#uses=1]
	%tmp.8 = call i32 @test2(i32 %tmp.10)		; <i32> [#uses=1]
	%DUMMY = add i32 %X, 1		; <i32> [#uses=0]
	ret i32 %tmp.8
}

; Though this case seems to be fairly unlikely to occur in the wild, someone
; plunked it into the demo script, so maybe they care about it.
define i32 @test3(i32 %c) {
; CHECK: i32 @test3
; CHECK: tailrecurse:
; CHECK: %ret.tr = phi i32 [ poison, %entry ], [ %current.ret.tr, %else ]
; CHECK: %ret.known.tr = phi i1 [ false, %entry ], [ true, %else ]
; CHECK: else:
; CHECK-NOT: call
; CHECK: %current.ret.tr = select i1 %ret.known.tr, i32 %ret.tr, i32 0
; CHECK-NOT: ret
; CHECK: return:
; CHECK: %current.ret.tr1 = select i1 %ret.known.tr, i32 %ret.tr, i32 0
; CHECK: ret i32 %current.ret.tr1
entry:
	%tmp.1 = icmp eq i32 %c, 0		; <i1> [#uses=1]
	br i1 %tmp.1, label %return, label %else
else:		; preds = %entry
	%tmp.5 = add i32 %c, -1		; <i32> [#uses=1]
	%tmp.3 = call i32 @test3(i32 %tmp.5)		; <i32> [#uses=0]
	ret i32 0
return:		; preds = %entry
	ret i32 0
}

; Make sure that a nocapture pointer does not stop adding a tail call marker to
; an unrelated call and additionally that we do not mark the nocapture call with
; a tail call.
;
; rdar://14324281
define void @test4() {
; CHECK: void @test4
; CHECK-NOT: tail call void @use_nocapture
; CHECK: tail call void @noarg()
; CHECK: ret void
  %a = alloca i32
  call void @use_nocapture(ptr %a)
  call void @noarg()
  ret void
}

; Make sure that we do not perform TRE even with a nocapture use. This is due to
; bad codegen caused by PR962.
;
; rdar://14324281.
define ptr @test5(ptr nocapture %A, i1 %cond) {
; CHECK: ptr @test5
; CHECK-NOT: tailrecurse:
; CHECK: ret ptr null
  %B = alloca i32
  br i1 %cond, label %cond_true, label %cond_false
cond_true:
  call ptr @test5(ptr %B, i1 false)
  ret ptr null
cond_false:
  call void @use2_nocapture(ptr %A, ptr %B)
  call void @noarg()
  ret ptr null
}

; PR14143: Make sure that we do not mark functions with nocapture allocas with tail.
;
; rdar://14324281.
define void @test6(ptr %a, ptr %b) {
; CHECK-LABEL: @test6(
; CHECK-NOT: tail call
; CHECK: ret void
  %c = alloca [100 x i8], align 16
  call void @use2_nocapture(ptr %b, ptr %c)
  ret void
}

; PR14143: Make sure that we do not mark functions with nocapture allocas with tail.
;
; rdar://14324281
define void @test7(ptr %a, ptr %b) nounwind uwtable {
entry:
; CHECK-LABEL: @test7(
; CHECK-NOT: tail call
; CHECK: ret void
  %c = alloca [100 x i8], align 16
  call void @use2_nocapture(ptr %c, ptr %a)
  call void @use2_nocapture(ptr %b, ptr %c)
  ret void
}

; If we have a mix of escaping captured/non-captured allocas, ensure that we do
; not do anything including marking callsites with the tail call marker.
;
; rdar://14324281.
define ptr @test8(ptr nocapture %A, i1 %cond) {
; CHECK: ptr @test8
; CHECK-NOT: tailrecurse:
; CHECK-NOT: tail call
; CHECK: ret ptr null
  %B = alloca i32
  %B2 = alloca i32
  br i1 %cond, label %cond_true, label %cond_false
cond_true:
  call void @use(ptr %B2)
  call ptr @test8(ptr %B, i1 false)
  ret ptr null
cond_false:
  call void @use2_nocapture(ptr %A, ptr %B)
  call void @noarg()
  ret ptr null
}

; Don't tail call if a byval arg is captured.
define void @test9(ptr byval(i32) %a) {
; CHECK-LABEL: define void @test9(
; CHECK: {{^ *}}call void @use(
  call void @use(ptr %a)
  ret void
}

%struct.X = type { ptr }

declare void @ctor(ptr)
define void @test10(ptr noalias sret(%struct.X) %agg.result, i1 zeroext %b) {
; CHECK-LABEL: @test10
entry:
  %x = alloca %struct.X, align 8
  br i1 %b, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  call void @ctor(ptr %agg.result)
; CHECK: tail call void @ctor
  br label %return

if.end:
  call void @ctor(ptr %x)
; CHECK: call void @ctor
  br label %return

return:
  ret void
}

declare void @test11_helper1(ptr nocapture, ptr)
declare void @test11_helper2(ptr)
define void @test11() {
; CHECK-LABEL: @test11
; CHECK-NOT: tail
  %a = alloca ptr
  %b = alloca i8
  call void @test11_helper1(ptr %a, ptr %b)  ; a = &b
  %c = load ptr, ptr %a
  call void @test11_helper2(ptr %c)
; CHECK: call void @test11_helper2
  ret void
}

; PR25928
define void @test12() {
entry:
; CHECK-LABEL: @test12
; CHECK: {{^ *}} call void undef(ptr undef) [ "foo"(ptr %e) ]
  %e = alloca i8
  call void undef(ptr undef) [ "foo"(ptr %e) ]
  unreachable
}

%struct.foo = type { [10 x i32] }

; If an alloca is passed byval it is not a use of the alloca or an escape
; point, and both calls below can be marked tail.
define void @test13() {
; CHECK-LABEL: @test13
; CHECK: tail call void @bar(ptr byval(%struct.foo) %f)
; CHECK: tail call void @bar(ptr byval(%struct.foo) null)
entry:
  %f = alloca %struct.foo
  call void @bar(ptr byval(%struct.foo) %f)
  call void @bar(ptr byval(%struct.foo) null)
  ret void
}

; A call which passes a byval parameter using byval can be marked tail.
define void @test14(ptr byval(%struct.foo) %f) {
; CHECK-LABEL: @test14
; CHECK: tail call void @bar
entry:
  call void @bar(ptr byval(%struct.foo) %f)
  ret void
}

; If a byval parameter is copied into an alloca and passed byval the call can
; be marked tail.
define void @test15(ptr byval(%struct.foo) %f) {
; CHECK-LABEL: @test15
; CHECK: tail call void @bar
entry:
  %agg.tmp = alloca %struct.foo
  call void @llvm.memcpy.p0.p0.i64(ptr %agg.tmp, ptr %f, i64 40, i1 false)
  call void @bar(ptr byval(%struct.foo) %agg.tmp)
  ret void
}

declare void @bar(ptr byval(%struct.foo))
declare void @llvm.memcpy.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1)