Justin Lebar | ccbd8f5 | 2016-02-22 18:24:43 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -basicaa -functionattrs -rpo-functionattrs -S | FileCheck %s |
Justin Lebar | 260854b | 2016-02-09 23:03:22 +0000 | [diff] [blame] | 2 | |
| 3 | ; CHECK: Function Attrs |
| 4 | ; CHECK-NOT: convergent |
| 5 | ; CHECK-NEXT: define i32 @nonleaf() |
| 6 | define i32 @nonleaf() convergent { |
| 7 | %a = call i32 @leaf() |
| 8 | ret i32 %a |
| 9 | } |
| 10 | |
| 11 | ; CHECK: Function Attrs |
| 12 | ; CHECK-NOT: convergent |
| 13 | ; CHECK-NEXT: define i32 @leaf() |
| 14 | define i32 @leaf() convergent { |
| 15 | ret i32 0 |
| 16 | } |
| 17 | |
| 18 | ; CHECK: Function Attrs |
| 19 | ; CHECK-SAME: convergent |
| 20 | ; CHECK-NEXT: declare i32 @k() |
| 21 | declare i32 @k() convergent |
| 22 | |
| 23 | ; CHECK: Function Attrs |
| 24 | ; CHECK-SAME: convergent |
| 25 | ; CHECK-NEXT: define i32 @extern() |
| 26 | define i32 @extern() convergent { |
| 27 | %a = call i32 @k() |
| 28 | ret i32 %a |
| 29 | } |
| 30 | |
| 31 | ; CHECK: Function Attrs |
| 32 | ; CHECK-SAME: convergent |
Justin Lebar | ccbd8f5 | 2016-02-22 18:24:43 +0000 | [diff] [blame] | 33 | ; CHECK-NEXT: define i32 @call_extern() |
| 34 | define i32 @call_extern() convergent { |
| 35 | %a = call i32 @extern() |
| 36 | ret i32 %a |
Justin Lebar | 260854b | 2016-02-09 23:03:22 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | ; CHECK: Function Attrs |
| 40 | ; CHECK-SAME: convergent |
| 41 | ; CHECK-NEXT: declare void @llvm.cuda.syncthreads() |
| 42 | declare void @llvm.cuda.syncthreads() convergent |
| 43 | |
| 44 | ; CHECK: Function Attrs |
| 45 | ; CHECK-SAME: convergent |
| 46 | ; CHECK-NEXT: define i32 @intrinsic() |
| 47 | define i32 @intrinsic() convergent { |
| 48 | call void @llvm.cuda.syncthreads() |
| 49 | ret i32 0 |
| 50 | } |
| 51 | |
Justin Lebar | ccbd8f5 | 2016-02-22 18:24:43 +0000 | [diff] [blame] | 52 | @xyz = global i32 ()* null |
| 53 | ; CHECK: Function Attrs |
| 54 | ; CHECK-SAME: convergent |
| 55 | ; CHECK-NEXT: define i32 @functionptr() |
| 56 | define i32 @functionptr() convergent { |
| 57 | %1 = load i32 ()*, i32 ()** @xyz |
| 58 | %2 = call i32 %1() |
| 59 | ret i32 %2 |
| 60 | } |
| 61 | |
Justin Lebar | 260854b | 2016-02-09 23:03:22 +0000 | [diff] [blame] | 62 | ; CHECK: Function Attrs |
| 63 | ; CHECK-NOT: convergent |
| 64 | ; CHECK-NEXT: define i32 @recursive1() |
| 65 | define i32 @recursive1() convergent { |
Justin Lebar | ccbd8f5 | 2016-02-22 18:24:43 +0000 | [diff] [blame] | 66 | %a = call i32 @recursive2() |
Justin Lebar | 260854b | 2016-02-09 23:03:22 +0000 | [diff] [blame] | 67 | ret i32 %a |
| 68 | } |
| 69 | |
| 70 | ; CHECK: Function Attrs |
| 71 | ; CHECK-NOT: convergent |
| 72 | ; CHECK-NEXT: define i32 @recursive2() |
| 73 | define i32 @recursive2() convergent { |
Justin Lebar | ccbd8f5 | 2016-02-22 18:24:43 +0000 | [diff] [blame] | 74 | %a = call i32 @recursive1() |
Justin Lebar | 260854b | 2016-02-09 23:03:22 +0000 | [diff] [blame] | 75 | ret i32 %a |
| 76 | } |
| 77 | |
| 78 | ; CHECK: Function Attrs |
| 79 | ; CHECK-SAME: convergent |
| 80 | ; CHECK-NEXT: define i32 @noopt() |
| 81 | define i32 @noopt() convergent optnone noinline { |
Justin Lebar | ccbd8f5 | 2016-02-22 18:24:43 +0000 | [diff] [blame] | 82 | %a = call i32 @noopt_friend() |
Justin Lebar | 260854b | 2016-02-09 23:03:22 +0000 | [diff] [blame] | 83 | ret i32 0 |
| 84 | } |
| 85 | |
| 86 | ; A function which is mutually-recursive with a convergent, optnone function |
| 87 | ; shouldn't have its convergent attribute stripped. |
| 88 | ; CHECK: Function Attrs |
| 89 | ; CHECK-SAME: convergent |
| 90 | ; CHECK-NEXT: define i32 @noopt_friend() |
| 91 | define i32 @noopt_friend() convergent { |
| 92 | %a = call i32 @noopt() |
| 93 | ret i32 0 |
| 94 | } |