1 ; RUN: opt -functionattrs -S < %s | FileCheck %s --check-prefix=FNATTR
2 ; RUN: opt -attributor -attributor-manifest-internal -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=6 -S < %s | FileCheck %s --check-prefix=ATTRIBUTOR
3 ; RUN: opt -attributor -attributor-manifest-internal -attributor-disable=false -functionattrs -S < %s | FileCheck %s --check-prefix=BOTH
5 ; Test cases specifically designed for the "returned" argument attribute.
6 ; We use FIXME's to indicate problems and missing attributes.
9 ; TEST SCC test returning an integer value argument
11 ; BOTH: Function Attrs: nofree noinline norecurse nosync nounwind readnone uwtable
12 ; BOTH-NEXT: define i32 @sink_r0(i32 returned %r)
13 ; BOTH: Function Attrs: nofree noinline nosync nounwind readnone uwtable
14 ; BOTH-NEXT: define i32 @scc_r1(i32 %a, i32 returned %r, i32 %b)
15 ; BOTH: Function Attrs: nofree noinline nosync nounwind readnone uwtable
16 ; BOTH-NEXT: define i32 @scc_r2(i32 %a, i32 %b, i32 returned %r)
17 ; BOTH: Function Attrs: nofree noinline nosync nounwind readnone uwtable
18 ; BOTH-NEXT: define i32 @scc_rX(i32 %a, i32 %b, i32 %r)
20 ; FNATTR: define i32 @sink_r0(i32 returned %r)
21 ; FNATTR: define i32 @scc_r1(i32 %a, i32 %r, i32 %b)
22 ; FNATTR: define i32 @scc_r2(i32 %a, i32 %b, i32 %r)
23 ; FNATTR: define i32 @scc_rX(i32 %a, i32 %b, i32 %r)
25 ; ATTRIBUTOR: define i32 @sink_r0(i32 returned %r)
26 ; ATTRIBUTOR: define i32 @scc_r1(i32 %a, i32 returned %r, i32 %b)
27 ; ATTRIBUTOR: define i32 @scc_r2(i32 %a, i32 %b, i32 returned %r)
28 ; ATTRIBUTOR: define i32 @scc_rX(i32 %a, i32 %b, i32 %r)
30 ; int scc_r1(int a, int b, int r);
31 ; int scc_r2(int a, int b, int r);
33 ; __attribute__((noinline)) int sink_r0(int r) {
37 ; __attribute__((noinline)) int scc_r1(int a, int r, int b) {
38 ; return scc_r2(r, a, sink_r0(r));
41 ; __attribute__((noinline)) int scc_r2(int a, int b, int r) {
43 ; return scc_r2(b, a, sink_r0(r));
45 ; return scc_r1(sink_r0(b), scc_r2(scc_r1(a, b, r), scc_r1(a, scc_r2(r, r, r), r), scc_r2(a, b, r)), scc_r1(a, b, r));
46 ; return a == b ? r : scc_r2(a, b, r);
48 ; __attribute__((noinline)) int scc_rX(int a, int b, int r) {
50 ; return scc_r2(b, a, sink_r0(r));
51 ; if (a < b) // V Diff to scc_r2
52 ; return scc_r1(sink_r0(b), scc_r2(scc_r1(a, b, r), scc_r1(a, scc_r2(r, r, r), r), scc_r1(a, b, r)), scc_r1(a, b, r));
53 ; return a == b ? r : scc_r2(a, b, r);
55 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
57 define i32 @sink_r0(i32 %r) #0 {
62 define i32 @scc_r1(i32 %a, i32 %r, i32 %b) #0 {
64 %call = call i32 @sink_r0(i32 %r)
65 %call1 = call i32 @scc_r2(i32 %r, i32 %a, i32 %call)
69 define i32 @scc_r2(i32 %a, i32 %b, i32 %r) #0 {
71 %cmp = icmp sgt i32 %a, %b
72 br i1 %cmp, label %if.then, label %if.end
74 if.then: ; preds = %entry
75 %call = call i32 @sink_r0(i32 %r)
76 %call1 = call i32 @scc_r2(i32 %b, i32 %a, i32 %call)
79 if.end: ; preds = %entry
80 %cmp2 = icmp slt i32 %a, %b
81 br i1 %cmp2, label %if.then3, label %if.end12
83 if.then3: ; preds = %if.end
84 %call4 = call i32 @sink_r0(i32 %b)
85 %call5 = call i32 @scc_r1(i32 %a, i32 %b, i32 %r)
86 %call6 = call i32 @scc_r2(i32 %r, i32 %r, i32 %r)
87 %call7 = call i32 @scc_r1(i32 %a, i32 %call6, i32 %r)
88 %call8 = call i32 @scc_r2(i32 %a, i32 %b, i32 %r)
89 %call9 = call i32 @scc_r2(i32 %call5, i32 %call7, i32 %call8)
90 %call10 = call i32 @scc_r1(i32 %a, i32 %b, i32 %r)
91 %call11 = call i32 @scc_r1(i32 %call4, i32 %call9, i32 %call10)
94 if.end12: ; preds = %if.end
95 %cmp13 = icmp eq i32 %a, %b
96 br i1 %cmp13, label %cond.true, label %cond.false
98 cond.true: ; preds = %if.end12
101 cond.false: ; preds = %if.end12
102 %call14 = call i32 @scc_r2(i32 %a, i32 %b, i32 %r)
105 cond.end: ; preds = %cond.false, %cond.true
106 %cond = phi i32 [ %r, %cond.true ], [ %call14, %cond.false ]
109 return: ; preds = %cond.end, %if.then3, %if.then
110 %retval.0 = phi i32 [ %call1, %if.then ], [ %call11, %if.then3 ], [ %cond, %cond.end ]
114 define i32 @scc_rX(i32 %a, i32 %b, i32 %r) #0 {
116 %cmp = icmp sgt i32 %a, %b
117 br i1 %cmp, label %if.then, label %if.end
119 if.then: ; preds = %entry
120 %call = call i32 @sink_r0(i32 %r)
121 %call1 = call i32 @scc_r2(i32 %b, i32 %a, i32 %call)
124 if.end: ; preds = %entry
125 %cmp2 = icmp slt i32 %a, %b
126 br i1 %cmp2, label %if.then3, label %if.end12
128 if.then3: ; preds = %if.end
129 %call4 = call i32 @sink_r0(i32 %b)
130 %call5 = call i32 @scc_r1(i32 %a, i32 %b, i32 %r)
131 %call6 = call i32 @scc_r2(i32 %r, i32 %r, i32 %r)
132 %call7 = call i32 @scc_r1(i32 %a, i32 %call6, i32 %r)
133 %call8 = call i32 @scc_r1(i32 %a, i32 %b, i32 %r)
134 %call9 = call i32 @scc_r2(i32 %call5, i32 %call7, i32 %call8)
135 %call10 = call i32 @scc_r1(i32 %a, i32 %b, i32 %r)
136 %call11 = call i32 @scc_r1(i32 %call4, i32 %call9, i32 %call10)
139 if.end12: ; preds = %if.end
140 %cmp13 = icmp eq i32 %a, %b
141 br i1 %cmp13, label %cond.true, label %cond.false
143 cond.true: ; preds = %if.end12
146 cond.false: ; preds = %if.end12
147 %call14 = call i32 @scc_r2(i32 %a, i32 %b, i32 %r)
150 cond.end: ; preds = %cond.false, %cond.true
151 %cond = phi i32 [ %r, %cond.true ], [ %call14, %cond.false ]
154 return: ; preds = %cond.end, %if.then3, %if.then
155 %retval.0 = phi i32 [ %call1, %if.then ], [ %call11, %if.then3 ], [ %cond, %cond.end ]
160 ; TEST SCC test returning a pointer value argument
162 ; BOTH: Function Attrs: nofree noinline norecurse nosync nounwind readnone uwtable
163 ; BOTH-NEXT: define double* @ptr_sink_r0(double* readnone returned "no-capture-maybe-returned" %r)
164 ; BOTH: Function Attrs: nofree noinline nosync nounwind readnone uwtable
165 ; BOTH-NEXT: define double* @ptr_scc_r1(double* %a, double* readnone returned %r, double* nocapture readnone %b)
166 ; BOTH: Function Attrs: nofree noinline nosync nounwind readnone uwtable
167 ; BOTH-NEXT: define double* @ptr_scc_r2(double* readnone %a, double* readnone %b, double* readnone returned %r)
169 ; FNATTR: define double* @ptr_sink_r0(double* readnone returned %r)
170 ; FNATTR: define double* @ptr_scc_r1(double* %a, double* readnone %r, double* nocapture readnone %b)
171 ; FNATTR: define double* @ptr_scc_r2(double* readnone %a, double* readnone %b, double* readnone %r)
173 ; ATTRIBUTOR: Function Attrs: nofree noinline nosync nounwind uwtable
174 ; ATTRIBUTOR-NEXT: define double* @ptr_sink_r0(double* returned "no-capture-maybe-returned" %r)
175 ; ATTRIBUTOR: Function Attrs: nofree noinline nosync nounwind uwtable
176 ; ATTRIBUTOR-NEXT: define double* @ptr_scc_r1(double* %a, double* returned %r, double* nocapture %b)
177 ; ATTRIBUTOR: Function Attrs: nofree noinline nosync nounwind uwtable
178 ; ATTRIBUTOR-NEXT: define double* @ptr_scc_r2(double* %a, double* %b, double* returned %r)
180 ; double* ptr_scc_r1(double* a, double* b, double* r);
181 ; double* ptr_scc_r2(double* a, double* b, double* r);
183 ; __attribute__((noinline)) double* ptr_sink_r0(double* r) {
187 ; __attribute__((noinline)) double* ptr_scc_r1(double* a, double* r, double* b) {
188 ; return ptr_scc_r2(r, a, ptr_sink_r0(r));
191 ; __attribute__((noinline)) double* ptr_scc_r2(double* a, double* b, double* r) {
193 ; return ptr_scc_r2(b, a, ptr_sink_r0(r));
195 ; return ptr_scc_r1(ptr_sink_r0(b), ptr_scc_r2(ptr_scc_r1(a, b, r), ptr_scc_r1(a, ptr_scc_r2(r, r, r), r), ptr_scc_r2(a, b, r)), ptr_scc_r1(a, b, r));
196 ; return a == b ? r : ptr_scc_r2(a, b, r);
198 define double* @ptr_sink_r0(double* %r) #0 {
203 define double* @ptr_scc_r1(double* %a, double* %r, double* %b) #0 {
205 %call = call double* @ptr_sink_r0(double* %r)
206 %call1 = call double* @ptr_scc_r2(double* %r, double* %a, double* %call)
210 define double* @ptr_scc_r2(double* %a, double* %b, double* %r) #0 {
212 %cmp = icmp ugt double* %a, %b
213 br i1 %cmp, label %if.then, label %if.end
215 if.then: ; preds = %entry
216 %call = call double* @ptr_sink_r0(double* %r)
217 %call1 = call double* @ptr_scc_r2(double* %b, double* %a, double* %call)
220 if.end: ; preds = %entry
221 %cmp2 = icmp ult double* %a, %b
222 br i1 %cmp2, label %if.then3, label %if.end12
224 if.then3: ; preds = %if.end
225 %call4 = call double* @ptr_sink_r0(double* %b)
226 %call5 = call double* @ptr_scc_r1(double* %a, double* %b, double* %r)
227 %call6 = call double* @ptr_scc_r2(double* %r, double* %r, double* %r)
228 %call7 = call double* @ptr_scc_r1(double* %a, double* %call6, double* %r)
229 %call8 = call double* @ptr_scc_r2(double* %a, double* %b, double* %r)
230 %call9 = call double* @ptr_scc_r2(double* %call5, double* %call7, double* %call8)
231 %call10 = call double* @ptr_scc_r1(double* %a, double* %b, double* %r)
232 %call11 = call double* @ptr_scc_r1(double* %call4, double* %call9, double* %call10)
235 if.end12: ; preds = %if.end
236 %cmp13 = icmp eq double* %a, %b
237 br i1 %cmp13, label %cond.true, label %cond.false
239 cond.true: ; preds = %if.end12
242 cond.false: ; preds = %if.end12
243 %call14 = call double* @ptr_scc_r2(double* %a, double* %b, double* %r)
246 cond.end: ; preds = %cond.false, %cond.true
247 %cond = phi double* [ %r, %cond.true ], [ %call14, %cond.false ]
250 return: ; preds = %cond.end, %if.then3, %if.then
251 %retval.0 = phi double* [ %call1, %if.then ], [ %call11, %if.then3 ], [ %cond, %cond.end ]
252 ret double* %retval.0
256 ; TEST a no-return singleton SCC
259 ; return *a ? a : rt0(a);
262 ; FNATTR: define i32* @rt0(i32* readonly %a)
263 ; BOTH: Function Attrs: nofree noinline noreturn nosync nounwind readonly uwtable
264 ; BOTH-NEXT: define noalias nonnull align 536870912 dereferenceable(4294967295) i32* @rt0(i32* nocapture readonly %a)
265 define i32* @rt0(i32* %a) #0 {
267 %v = load i32, i32* %a, align 4
268 %tobool = icmp ne i32 %v, 0
269 %call = call i32* @rt0(i32* %a)
270 %sel = select i1 %tobool, i32* %a, i32* %call
274 ; TEST a no-return singleton SCC
277 ; return *a ? undef : rt1(a);
280 ; FNATTR: define noalias i32* @rt1(i32* nocapture readonly %a)
281 ; BOTH: Function Attrs: nofree noinline noreturn nosync nounwind readonly uwtable
282 ; BOTH-NEXT: define noalias nonnull align 536870912 dereferenceable(4294967295) i32* @rt1(i32* nocapture readonly %a)
283 define i32* @rt1(i32* %a) #0 {
285 %v = load i32, i32* %a, align 4
286 %tobool = icmp ne i32 %v, 0
287 %call = call i32* @rt1(i32* %a)
288 %sel = select i1 %tobool, i32* undef, i32* %call
292 ; TEST another SCC test
294 ; FNATTR: define i32* @rt2_helper(i32* %a)
295 ; FNATTR: define i32* @rt2(i32* readnone %a, i32* readnone %b)
296 ; BOTH: define i32* @rt2_helper(i32* returned %a)
297 ; BOTH: define i32* @rt2(i32* readnone %a, i32* readnone "no-capture-maybe-returned" %b)
298 define i32* @rt2_helper(i32* %a) #0 {
300 %call = call i32* @rt2(i32* %a, i32* %a)
304 define i32* @rt2(i32* %a, i32 *%b) #0 {
306 %cmp = icmp eq i32* %a, null
307 br i1 %cmp, label %if.then, label %if.end
310 %call = call i32* @rt2_helper(i32* %a)
314 %sel = phi i32* [ %b, %entry], [%call, %if.then]
318 ; TEST another SCC test
320 ; FNATTR: define i32* @rt3_helper(i32* %a, i32* %b)
321 ; FNATTR: define i32* @rt3(i32* readnone %a, i32* readnone %b)
322 ; BOTH: define i32* @rt3_helper(i32* %a, i32* returned "no-capture-maybe-returned" %b)
323 ; BOTH: define i32* @rt3(i32* readnone %a, i32* readnone returned "no-capture-maybe-returned" %b)
324 define i32* @rt3_helper(i32* %a, i32* %b) #0 {
326 %call = call i32* @rt3(i32* %a, i32* %b)
330 define i32* @rt3(i32* %a, i32 *%b) #0 {
332 %cmp = icmp eq i32* %a, null
333 br i1 %cmp, label %if.then, label %if.end
336 %call = call i32* @rt3_helper(i32* %a, i32* %b)
340 %sel = phi i32* [ %b, %entry], [%call, %if.then]
344 ; TEST address taken function with call to an external functions
346 ; void unknown_fn(void *);
348 ; int* calls_unknown_fn(int *r) {
349 ; unknown_fn(&calls_unknown_fn);
353 ; BOTH: declare void @unknown_fn(i32* (i32*)*)
355 ; BOTH: Function Attrs: noinline nounwind uwtable
356 ; BOTH-NEXT: define i32* @calls_unknown_fn(i32* readnone returned "no-capture-maybe-returned" %r)
357 ; FNATTR: define i32* @calls_unknown_fn(i32* readnone returned %r)
358 ; ATTRIBUTOR: define i32* @calls_unknown_fn(i32* returned "no-capture-maybe-returned" %r)
359 declare void @unknown_fn(i32* (i32*)*) #0
361 define i32* @calls_unknown_fn(i32* %r) #0 {
362 tail call void @unknown_fn(i32* (i32*)* nonnull @calls_unknown_fn)
367 ; TEST call to a function that might be redifined at link time
369 ; int *maybe_redefined_fn(int *r) {
373 ; int *calls_maybe_redefined_fn(int *r) {
374 ; maybe_redefined_fn(r);
378 ; Verify the maybe-redefined function is not annotated:
380 ; CHECK: Function Attrs: noinline nounwind uwtable
381 ; CHECK: define linkonce_odr i32* @maybe_redefined_fn(i32* %r)
383 ; CHECK: Function Attrs: noinline nounwind uwtable
384 ; CHECK: define i32* @calls_maybe_redefined_fn(i32* returned %r)
386 ; BOTH: Function Attrs: noinline nounwind uwtable
387 ; BOTH-NEXT: define linkonce_odr i32* @maybe_redefined_fn(i32* %r)
389 ; BOTH: Function Attrs: noinline nounwind uwtable
390 ; BOTH-NEXT: define i32* @calls_maybe_redefined_fn(i32* returned %r)
391 define linkonce_odr i32* @maybe_redefined_fn(i32* %r) #0 {
396 define i32* @calls_maybe_redefined_fn(i32* %r) #0 {
398 %call = call i32* @maybe_redefined_fn(i32* %r)
402 ; TEST return call to a function that might be redifined at link time
404 ; int *maybe_redefined_fn2(int *r) {
408 ; int *calls_maybe_redefined_fn2(int *r) {
409 ; return maybe_redefined_fn2(r);
412 ; Verify the maybe-redefined function is not annotated:
414 ; BOTH: Function Attrs: noinline nounwind uwtable
415 ; BOTH-NEXT: define linkonce_odr i32* @maybe_redefined_fn2(i32* %r)
416 ; BOTH: Function Attrs: noinline nounwind uwtable
417 ; BOTH-NEXT: define i32* @calls_maybe_redefined_fn2(i32* %r)
419 ; FNATTR: define i32* @calls_maybe_redefined_fn2(i32* %r)
420 ; ATTRIBUTOR: define i32* @calls_maybe_redefined_fn2(i32* %r)
421 define linkonce_odr i32* @maybe_redefined_fn2(i32* %r) #0 {
426 define i32* @calls_maybe_redefined_fn2(i32* %r) #0 {
428 %call = call i32* @maybe_redefined_fn2(i32* %r)
433 ; TEST returned argument goes through select and phi
435 ; double select_and_phi(double b) {
439 ; return b == 0? b : x;
442 ; BOTH: Function Attrs: nofree noinline norecurse nosync nounwind readnone uwtable
443 ; BOTH-NEXT: define double @select_and_phi(double returned %b)
445 ; FNATTR: define double @select_and_phi(double %b)
446 ; ATTRIBUTOR: Function Attrs: nofree noinline nosync nounwind uwtable
447 ; ATTRIBUTOR-NEXT: define double @select_and_phi(double returned %b)
448 define double @select_and_phi(double %b) #0 {
450 %cmp = fcmp ogt double %b, 0.000000e+00
451 br i1 %cmp, label %if.then, label %if.end
453 if.then: ; preds = %entry
456 if.end: ; preds = %if.then, %entry
457 %phi = phi double [ %b, %if.then ], [ %b, %entry ]
458 %cmp1 = fcmp oeq double %b, 0.000000e+00
459 %sel = select i1 %cmp1, double %b, double %phi
464 ; TEST returned argument goes through recursion, select, and phi
466 ; double recursion_select_and_phi(int a, double b) {
469 ; x = recursion_select_and_phi(a, b);
470 ; return b == 0? b : x;
473 ; BOTH: Function Attrs: nofree noinline nosync nounwind readnone uwtable
474 ; BOTH-NEXT: define double @recursion_select_and_phi(i32 %a, double returned %b)
476 ; FNATTR: define double @recursion_select_and_phi(i32 %a, double %b)
478 ; ATTRIBUTOR: Function Attrs: nofree noinline nosync nounwind uwtable
479 ; ATTRIBUTOR-NEXT: define double @recursion_select_and_phi(i32 %a, double returned %b)
480 define double @recursion_select_and_phi(i32 %a, double %b) #0 {
482 %dec = add nsw i32 %a, -1
483 %cmp = icmp sgt i32 %a, 0
484 br i1 %cmp, label %if.then, label %if.end
486 if.then: ; preds = %entry
487 %call = call double @recursion_select_and_phi(i32 %dec, double %b)
490 if.end: ; preds = %if.then, %entry
491 %phi = phi double [ %call, %if.then ], [ %b, %entry ]
492 %cmp1 = fcmp oeq double %b, 0.000000e+00
493 %sel = select i1 %cmp1, double %b, double %phi
498 ; TEST returned argument goes through bitcasts
500 ; double* bitcast(int* b) {
504 ; BOTH: Function Attrs: nofree noinline norecurse nosync nounwind readnone uwtable
505 ; BOTH-NEXT: define double* @bitcast(i32* readnone returned "no-capture-maybe-returned" %b)
507 ; FNATTR: define double* @bitcast(i32* readnone %b)
509 ; ATTRIBUTOR: Function Attrs: nofree noinline nosync nounwind uwtable
510 ; ATTRIBUTOR-NEXT: define double* @bitcast(i32* returned "no-capture-maybe-returned" %b)
511 define double* @bitcast(i32* %b) #0 {
513 %bc0 = bitcast i32* %b to double*
518 ; TEST returned argument goes through select and phi interleaved with bitcasts
520 ; double* bitcasts_select_and_phi(int* b) {
524 ; return b != 0 ? b : x;
527 ; BOTH: Function Attrs: nofree noinline norecurse nosync nounwind readnone uwtable
528 ; BOTH-NEXT: define double* @bitcasts_select_and_phi(i32* readnone returned %b)
530 ; FNATTR: define double* @bitcasts_select_and_phi(i32* readnone %b)
532 ; ATTRIBUTOR: Function Attrs: nofree noinline nosync nounwind uwtable
533 ; ATTRIBUTOR-NEXT: define double* @bitcasts_select_and_phi(i32* returned %b)
534 define double* @bitcasts_select_and_phi(i32* %b) #0 {
536 %bc0 = bitcast i32* %b to double*
537 %cmp = icmp eq double* %bc0, null
538 br i1 %cmp, label %if.then, label %if.end
540 if.then: ; preds = %entry
541 %bc1 = bitcast i32* %b to double*
544 if.end: ; preds = %if.then, %entry
545 %phi = phi double* [ %bc1, %if.then ], [ %bc0, %entry ]
546 %bc2 = bitcast double* %phi to i8*
547 %bc3 = bitcast i32* %b to i8*
548 %cmp2 = icmp ne double* %bc0, null
549 %sel = select i1 %cmp2, i8* %bc2, i8* %bc3
550 %bc4 = bitcast i8* %sel to double*
555 ; TEST return argument or argument or undef
557 ; double* ret_arg_arg_undef(int* b) {
565 ; BOTH: Function Attrs: nofree noinline norecurse nosync nounwind readnone uwtable
566 ; BOTH-NEXT: define double* @ret_arg_arg_undef(i32* readnone returned %b)
568 ; FNATTR: define double* @ret_arg_arg_undef(i32* readnone %b)
570 ; ATTRIBUTOR: Function Attrs: nofree noinline nosync nounwind uwtable
571 ; ATTRIBUTOR-NEXT: define double* @ret_arg_arg_undef(i32* returned %b)
572 define double* @ret_arg_arg_undef(i32* %b) #0 {
574 %bc0 = bitcast i32* %b to double*
575 %cmp = icmp eq double* %bc0, null
576 br i1 %cmp, label %ret_arg0, label %if.end
579 %bc1 = bitcast i32* %b to double*
583 br i1 %cmp, label %ret_arg1, label %ret_undef
593 ; TEST return undef or argument or argument
595 ; double* ret_undef_arg_arg(int* b) {
603 ; BOTH: Function Attrs: nofree noinline norecurse nosync nounwind readnone uwtable
604 ; BOTH-NEXT: define double* @ret_undef_arg_arg(i32* readnone returned %b)
606 ; FNATTR: define double* @ret_undef_arg_arg(i32* readnone %b)
608 ; ATTRIBUTOR: Function Attrs: nofree noinline nosync nounwind uwtable
609 ; ATTRIBUTOR-NEXT: define double* @ret_undef_arg_arg(i32* returned %b)
610 define double* @ret_undef_arg_arg(i32* %b) #0 {
612 %bc0 = bitcast i32* %b to double*
613 %cmp = icmp eq double* %bc0, null
614 br i1 %cmp, label %ret_undef, label %if.end
620 br i1 %cmp, label %ret_arg0, label %ret_arg1
626 %bc1 = bitcast i32* %b to double*
631 ; TEST return undef or argument or undef
633 ; double* ret_undef_arg_undef(int* b) {
641 ; BOTH: Function Attrs: nofree noinline norecurse nosync nounwind readnone uwtable
642 ; BOTH-NEXT: define double* @ret_undef_arg_undef(i32* readnone returned %b)
644 ; FNATTR: define double* @ret_undef_arg_undef(i32* readnone %b)
645 ; ATTRIBUTOR: define double* @ret_undef_arg_undef(i32* returned %b)
646 define double* @ret_undef_arg_undef(i32* %b) #0 {
648 %bc0 = bitcast i32* %b to double*
649 %cmp = icmp eq double* %bc0, null
650 br i1 %cmp, label %ret_undef0, label %if.end
656 br i1 %cmp, label %ret_arg, label %ret_undef1
665 ; TEST return argument or unknown call result
667 ; int* ret_arg_or_unknown(int* b) {
673 ; Verify we do not assume b is returned
675 ; FNATTR: define i32* @ret_arg_or_unknown(i32* %b)
676 ; FNATTR: define i32* @ret_arg_or_unknown_through_phi(i32* %b)
677 ; ATTRIBUTOR: define i32* @ret_arg_or_unknown(i32* %b)
678 ; ATTRIBUTOR: define i32* @ret_arg_or_unknown_through_phi(i32* %b)
679 ; BOTH: define i32* @ret_arg_or_unknown(i32* %b)
680 ; BOTH: define i32* @ret_arg_or_unknown_through_phi(i32* %b)
681 declare i32* @unknown(i32*)
683 define i32* @ret_arg_or_unknown(i32* %b) #0 {
685 %cmp = icmp eq i32* %b, null
686 br i1 %cmp, label %ret_arg, label %ret_unknown
692 %call = call i32* @unknown(i32* %b)
696 define i32* @ret_arg_or_unknown_through_phi(i32* %b) #0 {
698 %cmp = icmp eq i32* %b, null
699 br i1 %cmp, label %ret_arg, label %ret_unknown
705 %call = call i32* @unknown(i32* %b)
709 %phi = phi i32* [ %b, %ret_arg ], [ %call, %ret_unknown ]
713 ; TEST inconsistent IR in dead code.
715 ; FNATTR: define i32 @deadblockcall1(i32 %A)
716 ; FNATTR: define i32 @deadblockcall2(i32 %A)
717 ; FNATTR: define i32 @deadblockphi1(i32 %A)
718 ; FNATTR: define i32 @deadblockphi2(i32 %A)
719 ; ATTRIBUTOR: define i32 @deadblockcall1(i32 returned %A)
720 ; ATTRIBUTOR: define i32 @deadblockcall2(i32 returned %A)
721 ; ATTRIBUTOR: define i32 @deadblockphi1(i32 returned %A)
722 ; ATTRIBUTOR: define i32 @deadblockphi2(i32 returned %A)
723 ; BOTH: define i32 @deadblockcall1(i32 returned %A)
724 ; BOTH: define i32 @deadblockcall2(i32 returned %A)
725 ; BOTH: define i32 @deadblockphi1(i32 returned %A)
726 ; BOTH: define i32 @deadblockphi2(i32 returned %A)
727 define i32 @deadblockcall1(i32 %A) #0 {
731 %B = call i32 @deadblockcall1(i32 %B)
735 declare i32 @deadblockcall_helper(i32 returned %A);
737 define i32 @deadblockcall2(i32 %A) #0 {
741 %B = call i32 @deadblockcall_helper(i32 %B)
744 %C = call i32 @deadblockcall1(i32 %C)
748 define i32 @deadblockphi1(i32 %A) #0 {
752 %B = call i32 @deadblockcall_helper(i32 %B)
755 %C = call i32 @deadblockcall1(i32 %C)
758 %PHI = phi i32 [%A, %entry], [%C, %unreachableblock2]
762 define i32 @deadblockphi2(i32 %A) #0 {
766 %B = call i32 @deadblockcall_helper(i32 %B)
767 br label %unreachableblock3
769 %C = call i32 @deadblockcall1(i32 %C)
770 br label %unreachableblock3
772 %PHI1 = phi i32 [%B, %unreachableblock1], [%C, %unreachableblock2]
775 %PHI2 = phi i32 [%A, %entry], [%PHI1, %unreachableblock3]
779 declare void @noreturn() noreturn;
781 define i32 @deadblockphi3(i32 %A, i1 %c) #0 {
783 br i1 %c, label %r, label %unreachablecall
785 call void @noreturn();
786 %B = call i32 @deadblockcall_helper(i32 0)
787 br label %unreachableblock3
789 %C = call i32 @deadblockcall1(i32 %C)
790 br label %unreachableblock3
792 %PHI1 = phi i32 [%B, %unreachablecall], [%C, %unreachableblock2]
795 %PHI2 = phi i32 [%A, %entry], [%PHI1, %unreachableblock3]
799 define weak_odr i32 @non_exact_0() {
802 define weak_odr i32 @non_exact_1(i32 %a) {
805 define weak_odr i32 @non_exact_2(i32 returned %a) {
808 define weak_odr i32* @non_exact_3(i32* align 32 returned %a) {
811 define i32 @exact(i32* %a) {
812 %c0 = call i32 @non_exact_0()
813 %c1 = call i32 @non_exact_1(i32 1)
814 %c2 = call i32 @non_exact_2(i32 2)
815 %c3 = call i32* @non_exact_3(i32* %a)
816 ; We can use the information of the weak function non_exact_3 because it was
817 ; given to us and not derived (the alignment of the returned argument).
818 ; CHECK: %c4 = load i32, i32* %c3, align 32
819 %c4 = load i32, i32* %c3
820 ; FIXME: %c2 and %c3 should be replaced but not %c0 or %c1!
821 ; CHECK: %add1 = add i32 %c0, %c1
822 ; CHECK: %add2 = add i32 %add1, %c2
823 ; CHECK: %add3 = add i32 %add2, %c3
824 %add1 = add i32 %c0, %c1
825 %add2 = add i32 %add1, %c2
826 %add3 = add i32 %add2, %c4
830 @G = external global i8
831 define i32* @ret_const() #0 {
832 %bc = bitcast i8* @G to i32*
835 define i32* @use_const() #0 {
836 %c = call i32* @ret_const()
837 ; CHECK: ret i32* bitcast (i8* @G to i32*)
841 attributes #0 = { noinline nounwind uwtable }
843 ; BOTH-NOT: attributes #
844 ; BOTH-DAG: attributes #{{[0-9]*}} = { nofree noinline norecurse nosync nounwind readnone uwtable willreturn }
845 ; BOTH-DAG: attributes #{{[0-9]*}} = { nofree noinline nosync nounwind readnone uwtable }
846 ; BOTH-DAG: attributes #{{[0-9]*}} = { nofree noinline noreturn nosync nounwind readonly uwtable }
847 ; BOTH-DAG: attributes #{{[0-9]*}} = { noinline nounwind uwtable }
848 ; BOTH-DAG: attributes #{{[0-9]*}} = { noreturn }
849 ; BOTH-DAG: attributes #{{[0-9]*}} = { nofree nosync willreturn }
850 ; BOTH-DAG: attributes #{{[0-9]*}} = { nofree nosync }
851 ; BOTH-DAG: attributes #{{[0-9]*}} = { nofree noreturn nosync }
852 ; BOTH-NOT: attributes #