Skip to content

Commit 55b9601

Browse files
ssahasrajgu222
authored andcommitted
[LLVM] [NFC] Add more tests for uniformity analysis
1 parent 0dbb9b5 commit 55b9601

File tree

3 files changed

+237
-0
lines changed

3 files changed

+237
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
;
2+
; RUN: opt -mtriple amdgcn-- -passes='print<uniformity>' -disable-output %s 2>&1 | FileCheck %s
3+
;
4+
;
5+
; Entry (div.cond)
6+
; / \
7+
; B0 B3
8+
; | |
9+
; B1 B4
10+
; | |
11+
; \ /
12+
; B5 (phi: divergent)
13+
; |
14+
; B6 (div.uni)
15+
; / \
16+
; B7 B9
17+
; | |
18+
; B8 B10
19+
; | |
20+
; \ /
21+
; B11 (phi: uniform)
22+
23+
24+
; CHECK-LABEL: 'test_ctrl_divergence':
25+
; CHECK-LABEL: BLOCK Entry
26+
; CHECK: DIVERGENT: %div.cond = icmp eq i32 %tid, 0
27+
; CHECK: DIVERGENT: br i1 %div.cond, label %B3, label %B0
28+
;
29+
; CHECK-LABEL: BLOCK B5
30+
; CHECK: DIVERGENT: %div_a = phi i32 [ %a0, %B1 ], [ %a1, %B4 ]
31+
; CHECK: DIVERGENT: %div_b = phi i32 [ %b0, %B1 ], [ %b1, %B4 ]
32+
;
33+
; CHECK-LABEL: BLOCK B6
34+
; CHECK-NOT: DIVERGENT: %uni.cond = icmp
35+
; CHECK-NOT: DIVERGENT: br i1 %div.cond
36+
;
37+
; CHECK-LABEL: BLOCK B11
38+
; CHECK-NOT: DIVERGENT: %div_d = phi i32
39+
40+
41+
define amdgpu_kernel void @test_ctrl_divergence(i32 %a, i32 %b, i32 %c, i32 %d) {
42+
Entry:
43+
%tid = call i32 @llvm.amdgcn.workitem.id.x()
44+
%div.cond = icmp eq i32 %tid, 0
45+
br i1 %div.cond, label %B3, label %B0 ; divergent branch
46+
47+
B0:
48+
%a0 = add i32 %a, 1
49+
br label %B1
50+
51+
B1:
52+
%b0 = add i32 %b, 2
53+
br label %B5
54+
55+
B3:
56+
%a1 = add i32 %a, 10
57+
br label %B4
58+
59+
B4:
60+
%b1 = add i32 %b, 20
61+
br label %B5
62+
63+
B5:
64+
%div_a = phi i32 [%a0, %B1], [%a1, %B4]
65+
%div_b = phi i32 [%b0, %B1], [%b1, %B4]
66+
br label %B6
67+
68+
B6:
69+
%uni.cond = icmp eq i32 %c, 0
70+
br i1 %uni.cond, label %B7, label %B9
71+
72+
B7:
73+
%d1 = add i32 %d, 1
74+
br label %B8
75+
76+
B8:
77+
br label %B11
78+
79+
B9:
80+
%d2 = add i32 %d, 3
81+
br label %B10
82+
83+
B10:
84+
br label %B11
85+
86+
B11:
87+
%div_d = phi i32 [%d1, %B8], [%d2, %B10]
88+
ret void
89+
}
90+
91+
92+
declare i32 @llvm.amdgcn.workitem.id.x() #0
93+
94+
attributes #0 = {nounwind readnone }
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
; RUN: opt %s -mtriple amdgcn-- -passes='print<uniformity>' -disable-output 2>&1 | FileCheck %s
2+
3+
define amdgpu_kernel void @cycle_inner_ipd(i32 %n, i32 %a, i32 %b) #0 {
4+
;
5+
; entry
6+
; / \
7+
; E2<------E1
8+
; | \ ^^
9+
; | \ / |
10+
; | v/ |
11+
; | A |
12+
; | / |
13+
; | / |
14+
; vv |
15+
; B------->C
16+
; |
17+
; X
18+
;
19+
;
20+
; CHECK-LABEL: BLOCK entry
21+
; CHECK: DIVERGENT: %tid = call i32 @llvm.amdgcn.workitem.id.x()
22+
; CHECK: DIVERGENT: %div.cond = icmp slt i32 %tid, 0
23+
; CHECK: END BLOCK
24+
;
25+
; CHECK-LABEL: BLOCK B
26+
; CHECK: DIVERGENT: %div.merge = phi i32 [ 0, %A ], [ %b, %E2 ]
27+
; CHECK: END BLOCK
28+
29+
entry:
30+
%tid = call i32 @llvm.amdgcn.workitem.id.x()
31+
%div.cond = icmp slt i32 %tid, 0
32+
%uni.cond = icmp slt i32 %a, 0
33+
%uni.cond1 = icmp slt i32 %a, 2
34+
%uni.cond2 = icmp slt i32 %a, 10
35+
br i1 %uni.cond, label %E2, label %E1
36+
37+
E1:
38+
br label %E2
39+
40+
E2:
41+
br i1 %uni.cond1, label %A, label %B
42+
43+
44+
A:
45+
br i1 %div.cond, label %E1, label %B
46+
47+
B:
48+
%div.merge = phi i32 [ 0, %A ], [ %b, %E2 ]
49+
br label %C
50+
51+
C:
52+
br i1 %uni.cond2, label %E1, label %X
53+
54+
X:
55+
ret void
56+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
; RUN: opt -mtriple amdgcn-- -passes='print<uniformity>' -disable-output %s 2>&1 | FileCheck %s
2+
3+
; Alpha (div.uni)
4+
; | \
5+
; Entry \
6+
; (div.cond)\
7+
; / \ \
8+
; B0 B3 |
9+
; | | |
10+
; B1 B4<-+
11+
; | |
12+
; B2 B5
13+
; / | |
14+
; / | B501
15+
; / | |
16+
; B201->B202 B502
17+
; \ /
18+
; B6 (phi: divergent)
19+
;
20+
;
21+
; CHECK-LABEL: 'test_ctrl_divergence':
22+
; CHECK-LABEL: BLOCK Entry
23+
; CHECK: DIVERGENT: %div.cond = icmp eq i32 %tid, 0
24+
; CHECK: DIVERGENT: br i1 %div.cond, label %B3, label %B0
25+
;
26+
; CHECK-LABEL: BLOCK B6
27+
; CHECK: DIVERGENT: %div_a = phi i32 [ %a0, %B202 ], [ %a1, %B502 ]
28+
; CHECK: DIVERGENT: %div_b = phi i32 [ %b0, %B202 ], [ %b1, %B502 ]
29+
; CHECK: DIVERGENT: %div_c = phi i32 [ %c0, %B202 ], [ %c1, %B502 ]
30+
31+
define amdgpu_kernel void @test_ctrl_divergence(i32 %a, i32 %b, i32 %c, i32 %d) {
32+
Alpha:
33+
%tid = call i32 @llvm.amdgcn.workitem.id.x()
34+
%div.uni = icmp eq i32 %a, 0
35+
br i1 %div.uni, label %Entry, label %B4
36+
37+
Entry:
38+
%div.cond = icmp eq i32 %tid, 0
39+
br i1 %div.cond, label %B3, label %B0 ; divergent branch
40+
41+
B0:
42+
br label %B1
43+
44+
B1:
45+
br label %B2
46+
47+
B2:
48+
%a0 = add i32 %a, 1
49+
%b0 = add i32 %b, 2
50+
%c0 = add i32 %c, 3
51+
br i1 %div.uni, label %B201, label %B202
52+
53+
B201:
54+
br label %B202
55+
56+
B202:
57+
br label %B6
58+
59+
B3:
60+
br label %B4
61+
62+
B4:
63+
%a1 = add i32 %a, 10
64+
%b1 = add i32 %b, 20
65+
%c1 = add i32 %c, 30
66+
br i1 %div.uni, label %B5, label %B501
67+
68+
B5:
69+
br label %B501
70+
71+
B501:
72+
br label %B502
73+
74+
B502:
75+
br label %B6
76+
77+
B6:
78+
%div_a = phi i32 [%a0, %B202], [%a1, %B502]
79+
%div_b = phi i32 [%b0, %B202], [%b1, %B502]
80+
%div_c = phi i32 [%c0, %B202], [%c1, %B502]
81+
ret void
82+
}
83+
84+
85+
declare i32 @llvm.amdgcn.workitem.id.x() #0
86+
87+
attributes #0 = {nounwind readnone }

0 commit comments

Comments
 (0)