1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -mtriple=amdgcn-- -amdgpu-atomic-optimizer-strategy=Iterative -passes='amdgpu-atomic-optimizer,verify<domtree>' %s | FileCheck -check-prefix=IR %s
4 define amdgpu_kernel void @uniform_value(ptr addrspace(1) , ptr addrspace(1) %val) #0 {
5 ; IR-LABEL: @uniform_value(
7 ; IR-NEXT: [[UNIFORM_VALUE_KERNARG_SEGMENT:%.*]] = call nonnull align 16 dereferenceable(52) ptr addrspace(4) @llvm.amdgcn.kernarg.segment.ptr()
8 ; IR-NEXT: [[OUT_KERNARG_OFFSET:%.*]] = getelementptr inbounds i8, ptr addrspace(4) [[UNIFORM_VALUE_KERNARG_SEGMENT]], i64 36
9 ; IR-NEXT: [[LOADED_OUT_KERNARG_OFFSET:%.*]] = load <2 x i64>, ptr addrspace(4) [[OUT_KERNARG_OFFSET]], align 4
10 ; IR-NEXT: [[OUT_LOAD1:%.*]] = extractelement <2 x i64> [[LOADED_OUT_KERNARG_OFFSET]], i32 0
11 ; IR-NEXT: [[MEM_LOCATION:%.*]] = inttoptr i64 [[OUT_LOAD1]] to ptr addrspace(1)
12 ; IR-NEXT: [[VAL_LOAD2:%.*]] = extractelement <2 x i64> [[LOADED_OUT_KERNARG_OFFSET]], i32 1
13 ; IR-NEXT: [[VALUE_ADDRESS:%.*]] = inttoptr i64 [[VAL_LOAD2]] to ptr addrspace(1)
14 ; IR-NEXT: [[LANE:%.*]] = tail call i32 @llvm.amdgcn.workgroup.id.x()
15 ; IR-NEXT: [[IDXPROM:%.*]] = sext i32 [[LANE]] to i64
16 ; IR-NEXT: [[ELE:%.*]] = getelementptr i32, ptr addrspace(1) [[VALUE_ADDRESS]], i64 [[IDXPROM]]
17 ; IR-NEXT: [[VALUE:%.*]] = load i32, ptr addrspace(1) [[ELE]], align 4
18 ; IR-NEXT: [[GEP:%.*]] = getelementptr i32, ptr addrspace(1) [[MEM_LOCATION]], i32 4
19 ; IR-NEXT: [[TMP1:%.*]] = call i64 @llvm.amdgcn.ballot.i64(i1 true)
20 ; IR-NEXT: [[TMP2:%.*]] = trunc i64 [[TMP1]] to i32
21 ; IR-NEXT: [[TMP3:%.*]] = lshr i64 [[TMP1]], 32
22 ; IR-NEXT: [[TMP4:%.*]] = trunc i64 [[TMP3]] to i32
23 ; IR-NEXT: [[TMP5:%.*]] = call i32 @llvm.amdgcn.mbcnt.lo(i32 [[TMP2]], i32 0)
24 ; IR-NEXT: [[TMP6:%.*]] = call i32 @llvm.amdgcn.mbcnt.hi(i32 [[TMP4]], i32 [[TMP5]])
25 ; IR-NEXT: [[TMP7:%.*]] = call i64 @llvm.ctpop.i64(i64 [[TMP1]])
26 ; IR-NEXT: [[TMP8:%.*]] = trunc i64 [[TMP7]] to i32
27 ; IR-NEXT: [[TMP9:%.*]] = mul i32 [[VALUE]], [[TMP8]]
28 ; IR-NEXT: [[TMP10:%.*]] = icmp eq i32 [[TMP6]], 0
29 ; IR-NEXT: br i1 [[TMP10]], label [[TMP11:%.*]], label [[TMP13:%.*]]
31 ; IR-NEXT: [[TMP12:%.*]] = atomicrmw volatile add ptr addrspace(1) [[GEP]], i32 [[TMP9]] seq_cst, align 4
32 ; IR-NEXT: br label [[TMP13]]
37 %uniform_value.kernarg.segment = call nonnull align 16 dereferenceable(52) ptr addrspace(4) @llvm.amdgcn.kernarg.segment.ptr()
38 %out.kernarg.offset = getelementptr inbounds i8, ptr addrspace(4) %uniform_value.kernarg.segment, i64 36
39 %loaded.out.kernarg.offset = load <2 x i64>, ptr addrspace(4) %out.kernarg.offset, align 4
40 %out.load1 = extractelement <2 x i64> %loaded.out.kernarg.offset, i32 0
41 %mem.location = inttoptr i64 %out.load1 to ptr addrspace(1)
42 %val.load2 = extractelement <2 x i64> %loaded.out.kernarg.offset, i32 1
43 %value.address = inttoptr i64 %val.load2 to ptr addrspace(1)
44 %lane = tail call i32 @llvm.amdgcn.workgroup.id.x()
45 %idxprom = sext i32 %lane to i64
46 %ele = getelementptr i32, ptr addrspace(1) %value.address, i64 %idxprom
47 %value = load i32, ptr addrspace(1) %ele, align 4
48 %gep = getelementptr i32, ptr addrspace(1) %mem.location, i32 4
49 %old = atomicrmw volatile add ptr addrspace(1) %gep, i32 %value seq_cst, align 4
53 define amdgpu_kernel void @divergent_value(ptr addrspace(1) %out, ptr addrspace(1) %val) #0 {
54 ; IR-LABEL: @divergent_value(
56 ; IR-NEXT: [[DIVERGENT_VALUE_KERNARG_SEGMENT:%.*]] = call nonnull align 16 dereferenceable(52) ptr addrspace(4) @llvm.amdgcn.kernarg.segment.ptr()
57 ; IR-NEXT: [[OUT_KERNARG_OFFSET:%.*]] = getelementptr inbounds i8, ptr addrspace(4) [[DIVERGENT_VALUE_KERNARG_SEGMENT]], i64 36
58 ; IR-NEXT: [[LOADED_OUT_KERNARG_OFFSET:%.*]] = load <2 x i64>, ptr addrspace(4) [[OUT_KERNARG_OFFSET]], align 4
59 ; IR-NEXT: [[OUT_LOAD1:%.*]] = extractelement <2 x i64> [[LOADED_OUT_KERNARG_OFFSET]], i32 0
60 ; IR-NEXT: [[MEM_LOCATION:%.*]] = inttoptr i64 [[OUT_LOAD1]] to ptr addrspace(1)
61 ; IR-NEXT: [[VAL_LOAD2:%.*]] = extractelement <2 x i64> [[LOADED_OUT_KERNARG_OFFSET]], i32 1
62 ; IR-NEXT: [[VALUE_ADDRESS:%.*]] = inttoptr i64 [[VAL_LOAD2]] to ptr addrspace(1)
63 ; IR-NEXT: [[LANE:%.*]] = tail call i32 @llvm.amdgcn.workitem.id.x()
64 ; IR-NEXT: [[IDXPROM:%.*]] = sext i32 [[LANE]] to i64
65 ; IR-NEXT: [[ELE:%.*]] = getelementptr i32, ptr addrspace(1) [[VALUE_ADDRESS]], i64 [[IDXPROM]]
66 ; IR-NEXT: [[VALUE:%.*]] = load i32, ptr addrspace(1) [[ELE]], align 4
67 ; IR-NEXT: [[GEP:%.*]] = getelementptr i32, ptr addrspace(1) [[MEM_LOCATION]], i32 4
68 ; IR-NEXT: [[TMP0:%.*]] = call i64 @llvm.amdgcn.ballot.i64(i1 true)
69 ; IR-NEXT: [[TMP1:%.*]] = trunc i64 [[TMP0]] to i32
70 ; IR-NEXT: [[TMP2:%.*]] = lshr i64 [[TMP0]], 32
71 ; IR-NEXT: [[TMP3:%.*]] = trunc i64 [[TMP2]] to i32
72 ; IR-NEXT: [[TMP4:%.*]] = call i32 @llvm.amdgcn.mbcnt.lo(i32 [[TMP1]], i32 0)
73 ; IR-NEXT: [[TMP5:%.*]] = call i32 @llvm.amdgcn.mbcnt.hi(i32 [[TMP3]], i32 [[TMP4]])
74 ; IR-NEXT: [[TMP6:%.*]] = call i64 @llvm.amdgcn.ballot.i64(i1 true)
75 ; IR-NEXT: br label [[COMPUTELOOP:%.*]]
77 ; IR-NEXT: [[TMP8:%.*]] = atomicrmw volatile add ptr addrspace(1) [[GEP]], i32 [[TMP13:%.*]] seq_cst, align 4
78 ; IR-NEXT: br label [[TMP9:%.*]]
82 ; IR-NEXT: [[ACCUMULATOR:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[TMP13]], [[COMPUTELOOP]] ]
83 ; IR-NEXT: [[ACTIVEBITS:%.*]] = phi i64 [ [[TMP6]], [[ENTRY]] ], [ [[TMP16:%.*]], [[COMPUTELOOP]] ]
84 ; IR-NEXT: [[TMP10:%.*]] = call i64 @llvm.cttz.i64(i64 [[ACTIVEBITS]], i1 true)
85 ; IR-NEXT: [[TMP11:%.*]] = trunc i64 [[TMP10]] to i32
86 ; IR-NEXT: [[TMP12:%.*]] = call i32 @llvm.amdgcn.readlane.i32(i32 [[VALUE]], i32 [[TMP11]])
87 ; IR-NEXT: [[TMP13]] = add i32 [[ACCUMULATOR]], [[TMP12]]
88 ; IR-NEXT: [[TMP14:%.*]] = shl i64 1, [[TMP10]]
89 ; IR-NEXT: [[TMP15:%.*]] = xor i64 [[TMP14]], -1
90 ; IR-NEXT: [[TMP16]] = and i64 [[ACTIVEBITS]], [[TMP15]]
91 ; IR-NEXT: [[TMP17:%.*]] = icmp eq i64 [[TMP16]], 0
92 ; IR-NEXT: br i1 [[TMP17]], label [[COMPUTEEND:%.*]], label [[COMPUTELOOP]]
94 ; IR-NEXT: [[TMP18:%.*]] = icmp eq i32 [[TMP5]], 0
95 ; IR-NEXT: br i1 [[TMP18]], label [[TMP7:%.*]], label [[TMP9]]
98 %divergent_value.kernarg.segment = call nonnull align 16 dereferenceable(52) ptr addrspace(4) @llvm.amdgcn.kernarg.segment.ptr()
99 %out.kernarg.offset = getelementptr inbounds i8, ptr addrspace(4) %divergent_value.kernarg.segment, i64 36
100 %loaded.out.kernarg.offset = load <2 x i64>, ptr addrspace(4) %out.kernarg.offset, align 4
101 %out.load1 = extractelement <2 x i64> %loaded.out.kernarg.offset, i32 0
102 %mem.location = inttoptr i64 %out.load1 to ptr addrspace(1)
103 %val.load2 = extractelement <2 x i64> %loaded.out.kernarg.offset, i32 1
104 %value.address = inttoptr i64 %val.load2 to ptr addrspace(1)
105 %lane = tail call i32 @llvm.amdgcn.workitem.id.x()
106 %idxprom = sext i32 %lane to i64
107 %ele = getelementptr i32, ptr addrspace(1) %value.address, i64 %idxprom
108 %value = load i32, ptr addrspace(1) %ele, align 4
109 %gep = getelementptr i32, ptr addrspace(1) %mem.location, i32 4
110 %old = atomicrmw volatile add ptr addrspace(1) %gep, i32 %value seq_cst, align 4
114 declare i32 @llvm.amdgcn.workitem.id.x() #1
115 declare i32 @llvm.amdgcn.workgroup.id.x() #1
117 declare align 4 ptr addrspace(4) @llvm.amdgcn.kernarg.segment.ptr()
119 attributes #0 = {"target-cpu"="gfx906"}
120 attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none)}