1 ; RUN: opt -mtriple amdgcn-unknown-amdhsa -analyze -divergence -use-gpu-divergence-analysis %s | FileCheck %s
3 ; temporal-divergent use of value carried by divergent loop
4 define amdgpu_kernel void @temporal_diverge(i32 %n, i32 %a, i32 %b) #0 {
5 ; CHECK-LABEL: Printing analysis 'Legacy Divergence Analysis' for function 'temporal_diverge':
6 ; CHECK-NOT: DIVERGENT: %uni.
7 ; CHECK-NOT: DIVERGENT: br i1 %uni.
10 %tid = call i32 @llvm.amdgcn.workitem.id.x()
11 %uni.cond = icmp slt i32 %a, 0
15 %uni.merge.h = phi i32 [ 0, %entry ], [ %uni.inc, %H ]
16 %uni.inc = add i32 %uni.merge.h, 1
17 %div.exitx = icmp slt i32 %tid, 0
18 br i1 %div.exitx, label %X, label %H ; divergent branch
19 ; CHECK: DIVERGENT: %div.exitx =
20 ; CHECK: DIVERGENT: br i1 %div.exitx,
23 %div.user = add i32 %uni.inc, 5
27 ; temporal-divergent use of value carried by divergent loop inside a top-level loop
28 define amdgpu_kernel void @temporal_diverge_inloop(i32 %n, i32 %a, i32 %b) #0 {
29 ; CHECK-LABEL: Printing analysis 'Legacy Divergence Analysis' for function 'temporal_diverge_inloop':
30 ; CHECK-NOT: DIVERGENT: %uni.
31 ; CHECK-NOT: DIVERGENT: br i1 %uni.
34 %tid = call i32 @llvm.amdgcn.workitem.id.x()
35 %uni.cond = icmp slt i32 %a, 0
42 %uni.merge.h = phi i32 [ 0, %G ], [ %uni.inc, %H ]
43 %uni.inc = add i32 %uni.merge.h, 1
44 %div.exitx = icmp slt i32 %tid, 0
45 br i1 %div.exitx, label %X, label %H ; divergent branch
46 ; CHECK: DIVERGENT: %div.exitx =
47 ; CHECK: DIVERGENT: br i1 %div.exitx,
50 %div.user = add i32 %uni.inc, 5
51 br i1 %uni.cond, label %G, label %Y
54 %div.alsouser = add i32 %uni.inc, 5
59 ; temporal-uniform use of a valud, definition and users are carried by a surrounding divergent loop
60 define amdgpu_kernel void @temporal_uniform_indivloop(i32 %n, i32 %a, i32 %b) #0 {
61 ; CHECK-LABEL: Printing analysis 'Legacy Divergence Analysis' for function 'temporal_uniform_indivloop':
62 ; CHECK-NOT: DIVERGENT: %uni.
63 ; CHECK-NOT: DIVERGENT: br i1 %uni.
66 %tid = call i32 @llvm.amdgcn.workitem.id.x()
67 %uni.cond = icmp slt i32 %a, 0
74 %uni.merge.h = phi i32 [ 0, %G ], [ %uni.inc, %H ]
75 %uni.inc = add i32 %uni.merge.h, 1
76 br i1 %uni.cond, label %X, label %H ; divergent branch
79 %uni.user = add i32 %uni.inc, 5
80 %div.exity = icmp slt i32 %tid, 0
81 ; CHECK: DIVERGENT: %div.exity =
82 br i1 %div.exity, label %G, label %Y
83 ; CHECK: DIVERGENT: br i1 %div.exity,
86 %div.alsouser = add i32 %uni.inc, 5
91 ; temporal-divergent use of value carried by divergent loop, user is inside sibling loop
92 define amdgpu_kernel void @temporal_diverge_loopuser(i32 %n, i32 %a, i32 %b) #0 {
93 ; CHECK-LABEL: Printing analysis 'Legacy Divergence Analysis' for function 'temporal_diverge_loopuser':
94 ; CHECK-NOT: DIVERGENT: %uni.
95 ; CHECK-NOT: DIVERGENT: br i1 %uni.
98 %tid = call i32 @llvm.amdgcn.workitem.id.x()
99 %uni.cond = icmp slt i32 %a, 0
103 %uni.merge.h = phi i32 [ 0, %entry ], [ %uni.inc, %H ]
104 %uni.inc = add i32 %uni.merge.h, 1
105 %div.exitx = icmp slt i32 %tid, 0
106 br i1 %div.exitx, label %X, label %H ; divergent branch
107 ; CHECK: DIVERGENT: %div.exitx =
108 ; CHECK: DIVERGENT: br i1 %div.exitx,
114 %div.user = add i32 %uni.inc, 5
115 br i1 %uni.cond, label %G, label %Y
121 ; temporal-divergent use of value carried by divergent loop, user is inside sibling loop, defs and use are carried by a uniform loop
122 define amdgpu_kernel void @temporal_diverge_loopuser_nested(i32 %n, i32 %a, i32 %b) #0 {
123 ; CHECK-LABEL: Printing analysis 'Legacy Divergence Analysis' for function 'temporal_diverge_loopuser_nested':
124 ; CHECK-NOT: DIVERGENT: %uni.
125 ; CHECK-NOT: DIVERGENT: br i1 %uni.
128 %tid = call i32 @llvm.amdgcn.workitem.id.x()
129 %uni.cond = icmp slt i32 %a, 0
133 %uni.merge.h = phi i32 [ 0, %entry ], [ %uni.inc, %H ]
134 %uni.inc = add i32 %uni.merge.h, 1
135 %div.exitx = icmp slt i32 %tid, 0
136 br i1 %div.exitx, label %X, label %H ; divergent branch
137 ; CHECK: DIVERGENT: %div.exitx =
138 ; CHECK: DIVERGENT: br i1 %div.exitx,
144 %div.user = add i32 %uni.inc, 5
145 br i1 %uni.cond, label %G, label %Y
152 declare i32 @llvm.amdgcn.workitem.id.x() #0
154 attributes #0 = { nounwind readnone }