1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -passes=atomic-expand %s | FileCheck -check-prefix=GFX90A %s
4 declare i32 @llvm.amdgcn.workitem.id.x()
6 define amdgpu_kernel void @divergent_cfg(ptr addrspace(1) %out, float %in) #0 {
7 ; GFX90A-LABEL: @divergent_cfg(
9 ; GFX90A-NEXT: [[TID:%.*]] = call i32 @llvm.amdgcn.workitem.id.x()
10 ; GFX90A-NEXT: [[D_CMP:%.*]] = icmp ult i32 [[TID]], 16
11 ; GFX90A-NEXT: br i1 [[D_CMP]], label [[IF:%.*]], label [[ELSE:%.*]]
13 ; GFX90A-NEXT: [[TMP0:%.*]] = load float, ptr addrspace(1) [[OUT:%.*]], align 4
14 ; GFX90A-NEXT: br label [[ATOMICRMW_START:%.*]]
15 ; GFX90A: atomicrmw.start:
16 ; GFX90A-NEXT: [[LOADED:%.*]] = phi float [ [[TMP0]], [[IF]] ], [ [[TMP4:%.*]], [[ATOMICRMW_START]] ]
17 ; GFX90A-NEXT: [[NEW:%.*]] = fadd float [[LOADED]], [[IN:%.*]]
18 ; GFX90A-NEXT: [[TMP1:%.*]] = bitcast float [[NEW]] to i32
19 ; GFX90A-NEXT: [[TMP2:%.*]] = bitcast float [[LOADED]] to i32
20 ; GFX90A-NEXT: [[TMP3:%.*]] = cmpxchg ptr addrspace(1) [[OUT]], i32 [[TMP2]], i32 [[TMP1]] seq_cst seq_cst, align 4
21 ; GFX90A-NEXT: [[SUCCESS:%.*]] = extractvalue { i32, i1 } [[TMP3]], 1
22 ; GFX90A-NEXT: [[NEWLOADED:%.*]] = extractvalue { i32, i1 } [[TMP3]], 0
23 ; GFX90A-NEXT: [[TMP4]] = bitcast i32 [[NEWLOADED]] to float
24 ; GFX90A-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]]
25 ; GFX90A: atomicrmw.end:
26 ; GFX90A-NEXT: br label [[ENDIF:%.*]]
28 ; GFX90A-NEXT: [[TMP5:%.*]] = load float, ptr addrspace(1) [[OUT]], align 4
29 ; GFX90A-NEXT: br label [[ATOMICRMW_START2:%.*]]
30 ; GFX90A: atomicrmw.start2:
31 ; GFX90A-NEXT: [[LOADED3:%.*]] = phi float [ [[TMP5]], [[ELSE]] ], [ [[TMP9:%.*]], [[ATOMICRMW_START2]] ]
32 ; GFX90A-NEXT: [[NEW4:%.*]] = fadd float [[LOADED3]], [[IN]]
33 ; GFX90A-NEXT: [[TMP6:%.*]] = bitcast float [[NEW4]] to i32
34 ; GFX90A-NEXT: [[TMP7:%.*]] = bitcast float [[LOADED3]] to i32
35 ; GFX90A-NEXT: [[TMP8:%.*]] = cmpxchg ptr addrspace(1) [[OUT]], i32 [[TMP7]], i32 [[TMP6]] seq_cst seq_cst, align 4
36 ; GFX90A-NEXT: [[SUCCESS5:%.*]] = extractvalue { i32, i1 } [[TMP8]], 1
37 ; GFX90A-NEXT: [[NEWLOADED6:%.*]] = extractvalue { i32, i1 } [[TMP8]], 0
38 ; GFX90A-NEXT: [[TMP9]] = bitcast i32 [[NEWLOADED6]] to float
39 ; GFX90A-NEXT: br i1 [[SUCCESS5]], label [[ATOMICRMW_END1:%.*]], label [[ATOMICRMW_START2]]
40 ; GFX90A: atomicrmw.end1:
41 ; GFX90A-NEXT: br label [[ENDIF]]
43 ; GFX90A-NEXT: [[COMBINE:%.*]] = phi float [ [[TMP4]], [[ATOMICRMW_END]] ], [ [[TMP9]], [[ATOMICRMW_END1]] ]
44 ; GFX90A-NEXT: store float [[COMBINE]], ptr addrspace(1) [[OUT]], align 4
45 ; GFX90A-NEXT: ret void
48 %tid = call i32 @llvm.amdgcn.workitem.id.x()
49 %d_cmp = icmp ult i32 %tid, 16
50 br i1 %d_cmp, label %if, label %else
53 %res_if = atomicrmw fadd ptr addrspace(1) %out, float %in seq_cst
57 %res_else = atomicrmw fadd ptr addrspace(1) %out, float %in seq_cst
61 %combine = phi float [%res_if, %if], [%res_else, %else]
62 store float %combine, ptr addrspace(1) %out
66 attributes #0 = { "denormal-fp-math-f32"="preserve-sign,preserve-sign" }