1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -S -codegenprepare -mtriple=amdgcn-amd-amdhsa -mcpu=gfx908 < %s | FileCheck -check-prefix=OPT %s
3; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx908 < %s | FileCheck -check-prefix=GCN %s
4
5; Make sure we match the addressing mode offset of globla.atomic.fadd intrinsics across blocks.
6
7define amdgpu_kernel void @test_sink_small_offset_global_atomic_fadd_f32(float addrspace(1)* %out, float addrspace(1)* %in) {
8; OPT-LABEL: @test_sink_small_offset_global_atomic_fadd_f32(
9; OPT-NEXT:  entry:
10; OPT-NEXT:    [[OUT_GEP:%.*]] = getelementptr float, float addrspace(1)* [[OUT:%.*]], i32 999999
11; OPT-NEXT:    [[TID:%.*]] = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) [[ATTR3:#.*]]
12; OPT-NEXT:    [[CMP:%.*]] = icmp eq i32 [[TID]], 0
13; OPT-NEXT:    br i1 [[CMP]], label [[ENDIF:%.*]], label [[IF:%.*]]
14; OPT:       if:
15; OPT-NEXT:    [[TMP0:%.*]] = bitcast float addrspace(1)* [[IN:%.*]] to i8 addrspace(1)*
16; OPT-NEXT:    [[SUNKADDR:%.*]] = getelementptr i8, i8 addrspace(1)* [[TMP0]], i64 28
17; OPT-NEXT:    [[TMP1:%.*]] = bitcast i8 addrspace(1)* [[SUNKADDR]] to float addrspace(1)*
18; OPT-NEXT:    [[FADD2:%.*]] = call float @llvm.amdgcn.global.atomic.fadd.f32.p1f32.f32(float addrspace(1)* [[TMP1]], float 2.000000e+00)
19; OPT-NEXT:    [[VAL:%.*]] = load volatile float, float addrspace(1)* undef, align 4
20; OPT-NEXT:    br label [[ENDIF]]
21; OPT:       endif:
22; OPT-NEXT:    [[X:%.*]] = phi float [ [[VAL]], [[IF]] ], [ 0.000000e+00, [[ENTRY:%.*]] ]
23; OPT-NEXT:    store float [[X]], float addrspace(1)* [[OUT_GEP]], align 4
24; OPT-NEXT:    ret void
25;
26; GCN-LABEL: test_sink_small_offset_global_atomic_fadd_f32:
27; GCN:       ; %bb.0: ; %entry
28; GCN-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
29; GCN-NEXT:    v_mbcnt_lo_u32_b32 v0, -1, 0
30; GCN-NEXT:    v_cmp_ne_u32_e32 vcc, 0, v0
31; GCN-NEXT:    v_mov_b32_e32 v0, 0
32; GCN-NEXT:    s_and_saveexec_b64 s[4:5], vcc
33; GCN-NEXT:    s_cbranch_execz BB0_2
34; GCN-NEXT:  ; %bb.1: ; %if
35; GCN-NEXT:    v_mov_b32_e32 v0, 0
36; GCN-NEXT:    v_mov_b32_e32 v1, 2.0
37; GCN-NEXT:    s_waitcnt lgkmcnt(0)
38; GCN-NEXT:    global_atomic_add_f32 v0, v1, s[2:3] offset:28
39; GCN-NEXT:    global_load_dword v0, v[0:1], off
40; GCN-NEXT:  BB0_2: ; %endif
41; GCN-NEXT:    s_or_b64 exec, exec, s[4:5]
42; GCN-NEXT:    v_mov_b32_e32 v1, 0x3d0000
43; GCN-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
44; GCN-NEXT:    global_store_dword v1, v0, s[0:1] offset:2300
45; GCN-NEXT:    s_endpgm
46entry:
47  %out.gep = getelementptr float, float addrspace(1)* %out, i32 999999
48  %in.gep = getelementptr float, float addrspace(1)* %in, i32 7
49  %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
50  %cmp = icmp eq i32 %tid, 0
51  br i1 %cmp, label %endif, label %if
52
53if:
54  %fadd2 = call float @llvm.amdgcn.global.atomic.fadd.f32.p1f32.f32(float addrspace(1)* %in.gep, float 2.0)
55  %val = load volatile float, float addrspace(1)* undef
56  br label %endif
57
58endif:
59  %x = phi float [ %val, %if ], [ 0.0, %entry ]
60  store float %x, float addrspace(1)* %out.gep
61  br label %done
62
63done:
64  ret void
65}
66
67declare i32 @llvm.amdgcn.mbcnt.lo(i32, i32) #1
68declare float @llvm.amdgcn.global.atomic.fadd.f32.p1f32.f32(float addrspace(1)* nocapture, float) #2
69
70attributes #0 = { argmemonly nounwind }
71attributes #1 = { nounwind readnone willreturn }
72attributes #2 = { argmemonly nounwind willreturn }
73