1 ; RUN: llc -mtriple=amdgcn--amdhsa -mcpu=gfx700 -verify-machineinstrs < %s | FileCheck %s
2 ; RUN: llc -mtriple=amdgcn--amdhsa -mcpu=gfx802 -verify-machineinstrs < %s | FileCheck %s
4 declare i32 @llvm.amdgcn.writelane(i32, i32, i32) #0
6 ; CHECK-LABEL: {{^}}test_writelane_sreg:
7 ; CHECK: v_writelane_b32 v{{[0-9]+}}, s{{[0-9]+}}, s{{[0-9]+}}
8 define amdgpu_kernel void @test_writelane_sreg(i32 addrspace(1)* %out, i32 %src0, i32 %src1) #1 {
9 %oldval = load i32, i32 addrspace(1)* %out
10 %writelane = call i32 @llvm.amdgcn.writelane(i32 %src0, i32 %src1, i32 %oldval)
11 store i32 %writelane, i32 addrspace(1)* %out, align 4
15 ; CHECK-LABEL: {{^}}test_writelane_imm_sreg:
16 ; CHECK: v_writelane_b32 v{{[0-9]+}}, 32, s{{[0-9]+}}
17 define amdgpu_kernel void @test_writelane_imm_sreg(i32 addrspace(1)* %out, i32 %src1) #1 {
18 %oldval = load i32, i32 addrspace(1)* %out
19 %writelane = call i32 @llvm.amdgcn.writelane(i32 32, i32 %src1, i32 %oldval)
20 store i32 %writelane, i32 addrspace(1)* %out, align 4
24 ; CHECK-LABEL: {{^}}test_writelane_vreg_lane:
25 ; CHECK: v_readfirstlane_b32 [[LANE:s[0-9]+]], v{{[0-9]+}}
26 ; CHECK: v_writelane_b32 v{{[0-9]+}}, 12, [[LANE]]
27 define amdgpu_kernel void @test_writelane_vreg_lane(i32 addrspace(1)* %out, <2 x i32> addrspace(1)* %in) #1 {
28 %tid = call i32 @llvm.amdgcn.workitem.id.x()
29 %gep.in = getelementptr <2 x i32>, <2 x i32> addrspace(1)* %in, i32 %tid
30 %args = load <2 x i32>, <2 x i32> addrspace(1)* %gep.in
31 %oldval = load i32, i32 addrspace(1)* %out
32 %lane = extractelement <2 x i32> %args, i32 1
33 %writelane = call i32 @llvm.amdgcn.writelane(i32 12, i32 %lane, i32 %oldval)
34 store i32 %writelane, i32 addrspace(1)* %out, align 4
38 ; TODO: m0 should be folded.
39 ; CHECK-LABEL: {{^}}test_writelane_m0_sreg:
40 ; CHECK: s_mov_b32 m0, -1
41 ; CHECK: s_mov_b32 [[COPY_M0:s[0-9]+]], m0
42 ; CHECK: v_writelane_b32 v{{[0-9]+}}, [[COPY_M0]], s{{[0-9]+}}
43 define amdgpu_kernel void @test_writelane_m0_sreg(i32 addrspace(1)* %out, i32 %src1) #1 {
44 %oldval = load i32, i32 addrspace(1)* %out
45 %m0 = call i32 asm "s_mov_b32 m0, -1", "={m0}"()
46 %writelane = call i32 @llvm.amdgcn.writelane(i32 %m0, i32 %src1, i32 %oldval)
47 store i32 %writelane, i32 addrspace(1)* %out, align 4
51 ; CHECK-LABEL: {{^}}test_writelane_imm:
52 ; CHECK: v_writelane_b32 v{{[0-9]+}}, s{{[0-9]+}}, 32
53 define amdgpu_kernel void @test_writelane_imm(i32 addrspace(1)* %out, i32 %src0) #1 {
54 %oldval = load i32, i32 addrspace(1)* %out
55 %writelane = call i32 @llvm.amdgcn.writelane(i32 %src0, i32 32, i32 %oldval) #0
56 store i32 %writelane, i32 addrspace(1)* %out, align 4
60 ; CHECK-LABEL: {{^}}test_writelane_sreg_oldval:
61 ; CHECK: v_mov_b32_e32 [[OLDVAL:v[0-9]+]], s{{[0-9]+}}
62 ; CHECK: v_writelane_b32 [[OLDVAL]], s{{[0-9]+}}, s{{[0-9]+}}
63 define amdgpu_kernel void @test_writelane_sreg_oldval(i32 inreg %oldval, i32 addrspace(1)* %out, i32 %src0, i32 %src1) #1 {
64 %writelane = call i32 @llvm.amdgcn.writelane(i32 %src0, i32 %src1, i32 %oldval)
65 store i32 %writelane, i32 addrspace(1)* %out, align 4
69 ; CHECK-LABEL: {{^}}test_writelane_imm_oldval:
70 ; CHECK: v_mov_b32_e32 [[OLDVAL:v[0-9]+]], 42
71 ; CHECK: v_writelane_b32 [[OLDVAL]], s{{[0-9]+}}, s{{[0-9]+}}
72 define amdgpu_kernel void @test_writelane_imm_oldval(i32 addrspace(1)* %out, i32 %src0, i32 %src1) #1 {
73 %writelane = call i32 @llvm.amdgcn.writelane(i32 %src0, i32 %src1, i32 42)
74 store i32 %writelane, i32 addrspace(1)* %out, align 4
78 declare i32 @llvm.amdgcn.workitem.id.x() #2
80 attributes #0 = { nounwind readnone convergent }
81 attributes #1 = { nounwind }
82 attributes #2 = { nounwind readnone }