blob: f673d91192b847ca46dec33613dd89adbf5120fc [file] [log] [blame]
Matt Arsenault9c47dd52016-02-11 06:02:01 +00001; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -check-prefix=SI %s
Matt Arsenaultfb826fa2013-11-18 20:09:47 +00002
3
Matt Arsenault9c47dd52016-02-11 06:02:01 +00004declare i32 @llvm.amdgcn.workitem.id.x() readnone
Matt Arsenaultfb826fa2013-11-18 20:09:47 +00005
Tom Stellard79243d92014-10-01 17:15:17 +00006; SI-LABEL: {{^}}test_i64_vreg:
Tom Stellard326d6ec2014-11-05 14:50:53 +00007; SI: v_add_i32
8; SI: v_addc_u32
Matt Arsenault3dbeefa2017-03-21 21:39:51 +00009define amdgpu_kernel void @test_i64_vreg(i64 addrspace(1)* noalias %out, i64 addrspace(1)* noalias %inA, i64 addrspace(1)* noalias %inB) {
Matt Arsenault9c47dd52016-02-11 06:02:01 +000010 %tid = call i32 @llvm.amdgcn.workitem.id.x() readnone
David Blaikie79e6c742015-02-27 19:29:02 +000011 %a_ptr = getelementptr i64, i64 addrspace(1)* %inA, i32 %tid
12 %b_ptr = getelementptr i64, i64 addrspace(1)* %inB, i32 %tid
David Blaikiea79ac142015-02-27 21:17:42 +000013 %a = load i64, i64 addrspace(1)* %a_ptr
14 %b = load i64, i64 addrspace(1)* %b_ptr
Matt Arsenaultfb826fa2013-11-18 20:09:47 +000015 %result = add i64 %a, %b
16 store i64 %result, i64 addrspace(1)* %out
17 ret void
18}
19
Matt Arsenault3a4d86a2013-11-18 20:09:55 +000020; Check that the SGPR add operand is correctly moved to a VGPR.
Tom Stellard79243d92014-10-01 17:15:17 +000021; SI-LABEL: {{^}}sgpr_operand:
Alexander Timofeev982aee62017-07-04 17:32:00 +000022; SI: s_add_u32
23; SI: s_addc_u32
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000024define amdgpu_kernel void @sgpr_operand(i64 addrspace(1)* noalias %out, i64 addrspace(1)* noalias %in, i64 addrspace(1)* noalias %in_bar, i64 %a) {
David Blaikiea79ac142015-02-27 21:17:42 +000025 %foo = load i64, i64 addrspace(1)* %in, align 8
Matt Arsenault08f7e372013-11-18 20:09:50 +000026 %result = add i64 %foo, %a
Matt Arsenaultfb826fa2013-11-18 20:09:47 +000027 store i64 %result, i64 addrspace(1)* %out
28 ret void
29}
30
Matt Arsenault08f7e372013-11-18 20:09:50 +000031; Swap the arguments. Check that the SGPR -> VGPR copy works with the
32; SGPR as other operand.
33;
Tom Stellard79243d92014-10-01 17:15:17 +000034; SI-LABEL: {{^}}sgpr_operand_reversed:
Alexander Timofeev982aee62017-07-04 17:32:00 +000035; SI: s_add_u32
36; SI: s_addc_u32
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000037define amdgpu_kernel void @sgpr_operand_reversed(i64 addrspace(1)* noalias %out, i64 addrspace(1)* noalias %in, i64 %a) {
David Blaikiea79ac142015-02-27 21:17:42 +000038 %foo = load i64, i64 addrspace(1)* %in, align 8
Matt Arsenault3a4d86a2013-11-18 20:09:55 +000039 %result = add i64 %a, %foo
40 store i64 %result, i64 addrspace(1)* %out
41 ret void
42}
Matt Arsenault08f7e372013-11-18 20:09:50 +000043
44
Tom Stellard79243d92014-10-01 17:15:17 +000045; SI-LABEL: {{^}}test_v2i64_sreg:
Tom Stellard326d6ec2014-11-05 14:50:53 +000046; SI: s_add_u32
47; SI: s_addc_u32
48; SI: s_add_u32
49; SI: s_addc_u32
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000050define amdgpu_kernel void @test_v2i64_sreg(<2 x i64> addrspace(1)* noalias %out, <2 x i64> %a, <2 x i64> %b) {
Matt Arsenaultfb826fa2013-11-18 20:09:47 +000051 %result = add <2 x i64> %a, %b
52 store <2 x i64> %result, <2 x i64> addrspace(1)* %out
53 ret void
54}
55
Tom Stellard79243d92014-10-01 17:15:17 +000056; SI-LABEL: {{^}}test_v2i64_vreg:
Tom Stellard326d6ec2014-11-05 14:50:53 +000057; SI: v_add_i32
58; SI: v_addc_u32
59; SI: v_add_i32
60; SI: v_addc_u32
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000061define amdgpu_kernel void @test_v2i64_vreg(<2 x i64> addrspace(1)* noalias %out, <2 x i64> addrspace(1)* noalias %inA, <2 x i64> addrspace(1)* noalias %inB) {
Matt Arsenault9c47dd52016-02-11 06:02:01 +000062 %tid = call i32 @llvm.amdgcn.workitem.id.x() readnone
David Blaikie79e6c742015-02-27 19:29:02 +000063 %a_ptr = getelementptr <2 x i64>, <2 x i64> addrspace(1)* %inA, i32 %tid
64 %b_ptr = getelementptr <2 x i64>, <2 x i64> addrspace(1)* %inB, i32 %tid
David Blaikiea79ac142015-02-27 21:17:42 +000065 %a = load <2 x i64>, <2 x i64> addrspace(1)* %a_ptr
66 %b = load <2 x i64>, <2 x i64> addrspace(1)* %b_ptr
Matt Arsenaultfb826fa2013-11-18 20:09:47 +000067 %result = add <2 x i64> %a, %b
68 store <2 x i64> %result, <2 x i64> addrspace(1)* %out
69 ret void
70}
Matt Arsenaultb517c812014-03-27 17:23:31 +000071
Tom Stellard79243d92014-10-01 17:15:17 +000072; SI-LABEL: {{^}}trunc_i64_add_to_i32:
Tom Stellard326d6ec2014-11-05 14:50:53 +000073; SI: s_load_dword s[[SREG0:[0-9]+]]
74; SI: s_load_dword s[[SREG1:[0-9]+]]
75; SI: s_add_i32 [[SRESULT:s[0-9]+]], s[[SREG1]], s[[SREG0]]
76; SI-NOT: addc
77; SI: v_mov_b32_e32 [[VRESULT:v[0-9]+]], [[SRESULT]]
78; SI: buffer_store_dword [[VRESULT]],
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000079define amdgpu_kernel void @trunc_i64_add_to_i32(i32 addrspace(1)* %out, i64 %a, i64 %b) {
Matt Arsenaultb517c812014-03-27 17:23:31 +000080 %add = add i64 %b, %a
81 %trunc = trunc i64 %add to i32
82 store i32 %trunc, i32 addrspace(1)* %out, align 8
83 ret void
84}