summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/FunctionAttrs/convergent.ll
blob: 46370d7bf30344fdfaf7ddd11829ede11a9cab87 (plain)
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
; RUN: opt < %s -basicaa -functionattrs -rpo-functionattrs -S | FileCheck %s

; CHECK: Function Attrs
; CHECK-NOT: convergent
; CHECK-NEXT: define i32 @nonleaf()
define i32 @nonleaf() convergent {
  %a = call i32 @leaf()
  ret i32 %a
}

; CHECK: Function Attrs
; CHECK-NOT: convergent
; CHECK-NEXT: define i32 @leaf()
define i32 @leaf() convergent {
  ret i32 0
}

; CHECK: Function Attrs
; CHECK-SAME: convergent
; CHECK-NEXT: declare i32 @k()
declare i32 @k() convergent

; CHECK: Function Attrs
; CHECK-SAME: convergent
; CHECK-NEXT: define i32 @extern()
define i32 @extern() convergent {
  %a = call i32 @k()
  ret i32 %a
}

; CHECK: Function Attrs
; CHECK-SAME: convergent
; CHECK-NEXT: define i32 @call_extern()
define i32 @call_extern() convergent {
  %a = call i32 @extern()
  ret i32 %a
}

; CHECK: Function Attrs
; CHECK-SAME: convergent
; CHECK-NEXT: declare void @llvm.cuda.syncthreads()
declare void @llvm.cuda.syncthreads() convergent

; CHECK: Function Attrs
; CHECK-SAME: convergent
; CHECK-NEXT: define i32 @intrinsic()
define i32 @intrinsic() convergent {
  call void @llvm.cuda.syncthreads()
  ret i32 0
}

@xyz = global i32 ()* null
; CHECK: Function Attrs
; CHECK-SAME: convergent
; CHECK-NEXT: define i32 @functionptr()
define i32 @functionptr() convergent {
  %1 = load i32 ()*, i32 ()** @xyz
  %2 = call i32 %1()
  ret i32 %2
}

; CHECK: Function Attrs
; CHECK-NOT: convergent
; CHECK-NEXT: define i32 @recursive1()
define i32 @recursive1() convergent {
  %a = call i32 @recursive2()
  ret i32 %a
}

; CHECK: Function Attrs
; CHECK-NOT: convergent
; CHECK-NEXT: define i32 @recursive2()
define i32 @recursive2() convergent {
  %a = call i32 @recursive1()
  ret i32 %a
}

; CHECK: Function Attrs
; CHECK-SAME: convergent
; CHECK-NEXT: define i32 @noopt()
define i32 @noopt() convergent optnone noinline {
  %a = call i32 @noopt_friend()
  ret i32 0
}

; A function which is mutually-recursive with a convergent, optnone function
; shouldn't have its convergent attribute stripped.
; CHECK: Function Attrs
; CHECK-SAME: convergent
; CHECK-NEXT: define i32 @noopt_friend()
define i32 @noopt_friend() convergent {
  %a = call i32 @noopt()
  ret i32 0
}
OpenPOWER on IntegriCloud