blob: 219684c753946ff12ccd9b9c2ee6bbdf1a8e1725 [file] [log] [blame]
Matt Arsenaultf0783302015-02-21 21:29:10 +00001; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=SI %s
2; XUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=VI %s
3
Matt Arsenault9c47dd52016-02-11 06:02:01 +00004declare i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
Matt Arsenaultf0783302015-02-21 21:29:10 +00005declare float @llvm.fabs.f32(float) nounwind readnone
6
7; GCN-LABEL: {{^}}madmk_f32:
8; GCN-DAG: buffer_load_dword [[VA:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}}
9; GCN-DAG: buffer_load_dword [[VB:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:4
Nikolay Haustov65607812016-03-11 09:27:25 +000010; GCN: v_madmk_f32_e32 {{v[0-9]+}}, [[VA]], 0x41200000, [[VB]]
Matt Arsenaultf0783302015-02-21 21:29:10 +000011define void @madmk_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in) nounwind {
Matt Arsenault9c47dd52016-02-11 06:02:01 +000012 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
David Blaikie79e6c742015-02-27 19:29:02 +000013 %gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid
14 %gep.1 = getelementptr float, float addrspace(1)* %gep.0, i32 1
15 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
Matt Arsenaultf0783302015-02-21 21:29:10 +000016
Matt Arsenault44e54832016-04-12 13:38:18 +000017 %a = load volatile float, float addrspace(1)* %gep.0, align 4
18 %b = load volatile float, float addrspace(1)* %gep.1, align 4
Matt Arsenaultf0783302015-02-21 21:29:10 +000019
20 %mul = fmul float %a, 10.0
21 %madmk = fadd float %mul, %b
22 store float %madmk, float addrspace(1)* %out.gep, align 4
23 ret void
24}
25
26; GCN-LABEL: {{^}}madmk_2_use_f32:
27; GCN-DAG: buffer_load_dword [[VA:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}}
28; GCN-DAG: buffer_load_dword [[VB:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:4
29; GCN-DAG: buffer_load_dword [[VC:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:8
30; GCN-DAG: v_mov_b32_e32 [[VK:v[0-9]+]], 0x41200000
Tom Stellarddb5a11f2015-07-13 15:47:57 +000031; GCN-DAG: v_mac_f32_e32 [[VB]], [[VK]], [[VA]]
32; GCN-DAG: v_mac_f32_e32 [[VC]], [[VK]], [[VA]]
Matt Arsenaultf0783302015-02-21 21:29:10 +000033; GCN: s_endpgm
34define void @madmk_2_use_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in) nounwind {
Matt Arsenault9c47dd52016-02-11 06:02:01 +000035 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
Matt Arsenaultf0783302015-02-21 21:29:10 +000036
David Blaikie79e6c742015-02-27 19:29:02 +000037 %in.gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid
38 %in.gep.1 = getelementptr float, float addrspace(1)* %in.gep.0, i32 1
39 %in.gep.2 = getelementptr float, float addrspace(1)* %in.gep.0, i32 2
Matt Arsenaultf0783302015-02-21 21:29:10 +000040
David Blaikie79e6c742015-02-27 19:29:02 +000041 %out.gep.0 = getelementptr float, float addrspace(1)* %out, i32 %tid
42 %out.gep.1 = getelementptr float, float addrspace(1)* %in.gep.0, i32 1
Matt Arsenaultf0783302015-02-21 21:29:10 +000043
Matt Arsenault44e54832016-04-12 13:38:18 +000044 %a = load volatile float, float addrspace(1)* %in.gep.0, align 4
45 %b = load volatile float, float addrspace(1)* %in.gep.1, align 4
46 %c = load volatile float, float addrspace(1)* %in.gep.2, align 4
Matt Arsenaultf0783302015-02-21 21:29:10 +000047
48 %mul0 = fmul float %a, 10.0
49 %mul1 = fmul float %a, 10.0
50 %madmk0 = fadd float %mul0, %b
51 %madmk1 = fadd float %mul1, %c
52
53 store float %madmk0, float addrspace(1)* %out.gep.0, align 4
54 store float %madmk1, float addrspace(1)* %out.gep.1, align 4
55 ret void
56}
57
58; We don't get any benefit if the constant is an inline immediate.
59; GCN-LABEL: {{^}}madmk_inline_imm_f32:
60; GCN-DAG: buffer_load_dword [[VA:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}}
61; GCN-DAG: buffer_load_dword [[VB:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:4
Tom Stellarddb5a11f2015-07-13 15:47:57 +000062; GCN: v_mac_f32_e32 [[VB]], 4.0, [[VA]]
Matt Arsenaultf0783302015-02-21 21:29:10 +000063define void @madmk_inline_imm_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in) nounwind {
Matt Arsenault9c47dd52016-02-11 06:02:01 +000064 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
David Blaikie79e6c742015-02-27 19:29:02 +000065 %gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid
66 %gep.1 = getelementptr float, float addrspace(1)* %gep.0, i32 1
67 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
Matt Arsenaultf0783302015-02-21 21:29:10 +000068
Matt Arsenault44e54832016-04-12 13:38:18 +000069 %a = load volatile float, float addrspace(1)* %gep.0, align 4
70 %b = load volatile float, float addrspace(1)* %gep.1, align 4
Matt Arsenaultf0783302015-02-21 21:29:10 +000071
72 %mul = fmul float %a, 4.0
73 %madmk = fadd float %mul, %b
74 store float %madmk, float addrspace(1)* %out.gep, align 4
75 ret void
76}
77
78; GCN-LABEL: {{^}}s_s_madmk_f32:
79; GCN-NOT: v_madmk_f32
Tom Stellarddb5a11f2015-07-13 15:47:57 +000080; GCN: v_mac_f32_e32
Matt Arsenaultf0783302015-02-21 21:29:10 +000081; GCN: s_endpgm
82define void @s_s_madmk_f32(float addrspace(1)* noalias %out, float %a, float %b) nounwind {
Matt Arsenault9c47dd52016-02-11 06:02:01 +000083 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
David Blaikie79e6c742015-02-27 19:29:02 +000084 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
Matt Arsenaultf0783302015-02-21 21:29:10 +000085
86 %mul = fmul float %a, 10.0
87 %madmk = fadd float %mul, %b
88 store float %madmk, float addrspace(1)* %out.gep, align 4
89 ret void
90}
91
92; GCN-LABEL: {{^}}v_s_madmk_f32:
93; GCN-NOT: v_madmk_f32
94; GCN: v_mad_f32
95; GCN: s_endpgm
96define void @v_s_madmk_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in, float %b) nounwind {
Matt Arsenault9c47dd52016-02-11 06:02:01 +000097 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
David Blaikie79e6c742015-02-27 19:29:02 +000098 %gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid
99 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
David Blaikiea79ac142015-02-27 21:17:42 +0000100 %a = load float, float addrspace(1)* %gep.0, align 4
Matt Arsenaultf0783302015-02-21 21:29:10 +0000101
102 %mul = fmul float %a, 10.0
103 %madmk = fadd float %mul, %b
104 store float %madmk, float addrspace(1)* %out.gep, align 4
105 ret void
106}
107
108; GCN-LABEL: {{^}}scalar_vector_madmk_f32:
109; GCN-NOT: v_madmk_f32
Tom Stellarddb5a11f2015-07-13 15:47:57 +0000110; GCN: v_mac_f32_e32
Matt Arsenaultf0783302015-02-21 21:29:10 +0000111; GCN: s_endpgm
112define void @scalar_vector_madmk_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in, float %a) nounwind {
Matt Arsenault9c47dd52016-02-11 06:02:01 +0000113 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
David Blaikie79e6c742015-02-27 19:29:02 +0000114 %gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid
115 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
David Blaikiea79ac142015-02-27 21:17:42 +0000116 %b = load float, float addrspace(1)* %gep.0, align 4
Matt Arsenaultf0783302015-02-21 21:29:10 +0000117
118 %mul = fmul float %a, 10.0
119 %madmk = fadd float %mul, %b
120 store float %madmk, float addrspace(1)* %out.gep, align 4
121 ret void
122}
123
124; GCN-LABEL: {{^}}no_madmk_src0_modifier_f32:
125; GCN-DAG: buffer_load_dword [[VA:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}}
126; GCN-DAG: buffer_load_dword [[VB:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:4
127; GCN: v_mad_f32 {{v[0-9]+}}, |{{v[0-9]+}}|, {{v[0-9]+}}, {{[sv][0-9]+}}
128define void @no_madmk_src0_modifier_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in) nounwind {
Matt Arsenault9c47dd52016-02-11 06:02:01 +0000129 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
David Blaikie79e6c742015-02-27 19:29:02 +0000130 %gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid
131 %gep.1 = getelementptr float, float addrspace(1)* %gep.0, i32 1
132 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
Matt Arsenaultf0783302015-02-21 21:29:10 +0000133
Matt Arsenault44e54832016-04-12 13:38:18 +0000134 %a = load volatile float, float addrspace(1)* %gep.0, align 4
135 %b = load volatile float, float addrspace(1)* %gep.1, align 4
Matt Arsenaultf0783302015-02-21 21:29:10 +0000136
137 %a.fabs = call float @llvm.fabs.f32(float %a) nounwind readnone
138
139 %mul = fmul float %a.fabs, 10.0
140 %madmk = fadd float %mul, %b
141 store float %madmk, float addrspace(1)* %out.gep, align 4
142 ret void
143}
144
145; GCN-LABEL: {{^}}no_madmk_src2_modifier_f32:
146; GCN-DAG: buffer_load_dword [[VA:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}}
147; GCN-DAG: buffer_load_dword [[VB:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:4
148; GCN: v_mad_f32 {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}, |{{[sv][0-9]+}}|
149define void @no_madmk_src2_modifier_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in) nounwind {
Matt Arsenault9c47dd52016-02-11 06:02:01 +0000150 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
David Blaikie79e6c742015-02-27 19:29:02 +0000151 %gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid
152 %gep.1 = getelementptr float, float addrspace(1)* %gep.0, i32 1
153 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
Matt Arsenaultf0783302015-02-21 21:29:10 +0000154
Matt Arsenault44e54832016-04-12 13:38:18 +0000155 %a = load volatile float, float addrspace(1)* %gep.0, align 4
156 %b = load volatile float, float addrspace(1)* %gep.1, align 4
Matt Arsenaultf0783302015-02-21 21:29:10 +0000157
158 %b.fabs = call float @llvm.fabs.f32(float %b) nounwind readnone
159
160 %mul = fmul float %a, 10.0
161 %madmk = fadd float %mul, %b.fabs
162 store float %madmk, float addrspace(1)* %out.gep, align 4
163 ret void
164}
165
166; GCN-LABEL: {{^}}madmk_add_inline_imm_f32:
167; GCN: buffer_load_dword [[A:v[0-9]+]]
168; GCN: v_mov_b32_e32 [[VK:v[0-9]+]], 0x41200000
169; GCN: v_mad_f32 {{v[0-9]+}}, [[VK]], [[A]], 2.0
170define void @madmk_add_inline_imm_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in) nounwind {
Matt Arsenault9c47dd52016-02-11 06:02:01 +0000171 %tid = tail call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
David Blaikie79e6c742015-02-27 19:29:02 +0000172 %gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid
173 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
Matt Arsenaultf0783302015-02-21 21:29:10 +0000174
David Blaikiea79ac142015-02-27 21:17:42 +0000175 %a = load float, float addrspace(1)* %gep.0, align 4
Matt Arsenaultf0783302015-02-21 21:29:10 +0000176
177 %mul = fmul float %a, 10.0
178 %madmk = fadd float %mul, 2.0
179 store float %madmk, float addrspace(1)* %out.gep, align 4
180 ret void
181}
Matt Arsenault5e100162015-04-24 01:57:58 +0000182
183; SI-LABEL: {{^}}kill_madmk_verifier_error:
184; SI: s_xor_b64
Nikolay Haustov65607812016-03-11 09:27:25 +0000185; SI: v_madmk_f32_e32 {{v[0-9]+}}, {{v[0-9]+}}, 0x472aee8c, {{v[0-9]+}}
Matt Arsenault5e100162015-04-24 01:57:58 +0000186; SI: s_or_b64
187define void @kill_madmk_verifier_error() nounwind {
188bb:
189 br label %bb2
190
191bb1: ; preds = %bb2
192 ret void
193
194bb2: ; preds = %bb6, %bb
195 %tmp = phi float [ undef, %bb ], [ %tmp8, %bb6 ]
Tom Stellardbc4497b2016-02-12 23:45:29 +0000196 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #1
197 %f_tid = bitcast i32 %tid to float
198 %tmp3 = fsub float %f_tid, %tmp
Matt Arsenault5e100162015-04-24 01:57:58 +0000199 %tmp5 = fcmp oeq float %tmp3, 1.000000e+04
200 br i1 %tmp5, label %bb1, label %bb6
201
202bb6: ; preds = %bb2
203 %tmp4 = fmul float %tmp, undef
204 %tmp7 = fmul float %tmp4, 0x40E55DD180000000
205 %tmp8 = fadd float %tmp7, undef
206 br label %bb2
207}
Tom Stellardbc4497b2016-02-12 23:45:29 +0000208
209declare i32 @llvm.amdgcn.mbcnt.lo(i32, i32) #1
210
211attributes #1 = { nounwind readnone }