blob: 24ff23a4cfc1c400e5b083557510b699415f8f6e [file] [log] [blame]
Tom Stellard49f8bfd2015-01-06 18:00:21 +00001; RUN: llc -march=amdgcn -mcpu=SI -verify-machineinstrs < %s | FileCheck -check-prefix=SI -check-prefix=FUNC %s
Matt Arsenault8675db12014-08-29 16:01:14 +00002
3declare i32 @llvm.r600.read.tidig.x() #0
4declare float @llvm.fabs.f32(float) #0
5
Tom Stellard79243d92014-10-01 17:15:17 +00006; FUNC-LABEL: {{^}}mad_sub_f32:
Tom Stellard326d6ec2014-11-05 14:50:53 +00007; SI: buffer_load_dword [[REGA:v[0-9]+]]
8; SI: buffer_load_dword [[REGB:v[0-9]+]]
9; SI: buffer_load_dword [[REGC:v[0-9]+]]
10; SI: v_mad_f32 [[RESULT:v[0-9]+]], [[REGA]], [[REGB]], -[[REGC]]
11; SI: buffer_store_dword [[RESULT]]
Matt Arsenault8675db12014-08-29 16:01:14 +000012define void @mad_sub_f32(float addrspace(1)* noalias nocapture %out, float addrspace(1)* noalias nocapture readonly %ptr) #1 {
13 %tid = tail call i32 @llvm.r600.read.tidig.x() #0
14 %tid.ext = sext i32 %tid to i64
David Blaikie79e6c742015-02-27 19:29:02 +000015 %gep0 = getelementptr float, float addrspace(1)* %ptr, i64 %tid.ext
Matt Arsenault8675db12014-08-29 16:01:14 +000016 %add1 = add i64 %tid.ext, 1
David Blaikie79e6c742015-02-27 19:29:02 +000017 %gep1 = getelementptr float, float addrspace(1)* %ptr, i64 %add1
Matt Arsenault8675db12014-08-29 16:01:14 +000018 %add2 = add i64 %tid.ext, 2
David Blaikie79e6c742015-02-27 19:29:02 +000019 %gep2 = getelementptr float, float addrspace(1)* %ptr, i64 %add2
20 %outgep = getelementptr float, float addrspace(1)* %out, i64 %tid.ext
David Blaikiea79ac142015-02-27 21:17:42 +000021 %a = load float, float addrspace(1)* %gep0, align 4
22 %b = load float, float addrspace(1)* %gep1, align 4
23 %c = load float, float addrspace(1)* %gep2, align 4
Matt Arsenault8675db12014-08-29 16:01:14 +000024 %mul = fmul float %a, %b
25 %sub = fsub float %mul, %c
26 store float %sub, float addrspace(1)* %outgep, align 4
27 ret void
28}
29
Tom Stellard79243d92014-10-01 17:15:17 +000030; FUNC-LABEL: {{^}}mad_sub_inv_f32:
Tom Stellard326d6ec2014-11-05 14:50:53 +000031; SI: buffer_load_dword [[REGA:v[0-9]+]]
32; SI: buffer_load_dword [[REGB:v[0-9]+]]
33; SI: buffer_load_dword [[REGC:v[0-9]+]]
34; SI: v_mad_f32 [[RESULT:v[0-9]+]], -[[REGA]], [[REGB]], [[REGC]]
35; SI: buffer_store_dword [[RESULT]]
Matt Arsenault8675db12014-08-29 16:01:14 +000036define void @mad_sub_inv_f32(float addrspace(1)* noalias nocapture %out, float addrspace(1)* noalias nocapture readonly %ptr) #1 {
37 %tid = tail call i32 @llvm.r600.read.tidig.x() #0
38 %tid.ext = sext i32 %tid to i64
David Blaikie79e6c742015-02-27 19:29:02 +000039 %gep0 = getelementptr float, float addrspace(1)* %ptr, i64 %tid.ext
Matt Arsenault8675db12014-08-29 16:01:14 +000040 %add1 = add i64 %tid.ext, 1
David Blaikie79e6c742015-02-27 19:29:02 +000041 %gep1 = getelementptr float, float addrspace(1)* %ptr, i64 %add1
Matt Arsenault8675db12014-08-29 16:01:14 +000042 %add2 = add i64 %tid.ext, 2
David Blaikie79e6c742015-02-27 19:29:02 +000043 %gep2 = getelementptr float, float addrspace(1)* %ptr, i64 %add2
44 %outgep = getelementptr float, float addrspace(1)* %out, i64 %tid.ext
David Blaikiea79ac142015-02-27 21:17:42 +000045 %a = load float, float addrspace(1)* %gep0, align 4
46 %b = load float, float addrspace(1)* %gep1, align 4
47 %c = load float, float addrspace(1)* %gep2, align 4
Matt Arsenault8675db12014-08-29 16:01:14 +000048 %mul = fmul float %a, %b
49 %sub = fsub float %c, %mul
50 store float %sub, float addrspace(1)* %outgep, align 4
51 ret void
52}
53
Tom Stellard79243d92014-10-01 17:15:17 +000054; FUNC-LABEL: {{^}}mad_sub_f64:
Tom Stellard326d6ec2014-11-05 14:50:53 +000055; SI: v_mul_f64
56; SI: v_add_f64
Matt Arsenault8675db12014-08-29 16:01:14 +000057define void @mad_sub_f64(double addrspace(1)* noalias nocapture %out, double addrspace(1)* noalias nocapture readonly %ptr) #1 {
58 %tid = tail call i32 @llvm.r600.read.tidig.x() #0
59 %tid.ext = sext i32 %tid to i64
David Blaikie79e6c742015-02-27 19:29:02 +000060 %gep0 = getelementptr double, double addrspace(1)* %ptr, i64 %tid.ext
Matt Arsenault8675db12014-08-29 16:01:14 +000061 %add1 = add i64 %tid.ext, 1
David Blaikie79e6c742015-02-27 19:29:02 +000062 %gep1 = getelementptr double, double addrspace(1)* %ptr, i64 %add1
Matt Arsenault8675db12014-08-29 16:01:14 +000063 %add2 = add i64 %tid.ext, 2
David Blaikie79e6c742015-02-27 19:29:02 +000064 %gep2 = getelementptr double, double addrspace(1)* %ptr, i64 %add2
65 %outgep = getelementptr double, double addrspace(1)* %out, i64 %tid.ext
David Blaikiea79ac142015-02-27 21:17:42 +000066 %a = load double, double addrspace(1)* %gep0, align 8
67 %b = load double, double addrspace(1)* %gep1, align 8
68 %c = load double, double addrspace(1)* %gep2, align 8
Matt Arsenault8675db12014-08-29 16:01:14 +000069 %mul = fmul double %a, %b
70 %sub = fsub double %mul, %c
71 store double %sub, double addrspace(1)* %outgep, align 8
72 ret void
73}
74
Tom Stellard79243d92014-10-01 17:15:17 +000075; FUNC-LABEL: {{^}}mad_sub_fabs_f32:
Tom Stellard326d6ec2014-11-05 14:50:53 +000076; SI: buffer_load_dword [[REGA:v[0-9]+]]
77; SI: buffer_load_dword [[REGB:v[0-9]+]]
78; SI: buffer_load_dword [[REGC:v[0-9]+]]
79; SI: v_mad_f32 [[RESULT:v[0-9]+]], [[REGA]], [[REGB]], -|[[REGC]]|
80; SI: buffer_store_dword [[RESULT]]
Matt Arsenault8675db12014-08-29 16:01:14 +000081define void @mad_sub_fabs_f32(float addrspace(1)* noalias nocapture %out, float addrspace(1)* noalias nocapture readonly %ptr) #1 {
82 %tid = tail call i32 @llvm.r600.read.tidig.x() #0
83 %tid.ext = sext i32 %tid to i64
David Blaikie79e6c742015-02-27 19:29:02 +000084 %gep0 = getelementptr float, float addrspace(1)* %ptr, i64 %tid.ext
Matt Arsenault8675db12014-08-29 16:01:14 +000085 %add1 = add i64 %tid.ext, 1
David Blaikie79e6c742015-02-27 19:29:02 +000086 %gep1 = getelementptr float, float addrspace(1)* %ptr, i64 %add1
Matt Arsenault8675db12014-08-29 16:01:14 +000087 %add2 = add i64 %tid.ext, 2
David Blaikie79e6c742015-02-27 19:29:02 +000088 %gep2 = getelementptr float, float addrspace(1)* %ptr, i64 %add2
89 %outgep = getelementptr float, float addrspace(1)* %out, i64 %tid.ext
David Blaikiea79ac142015-02-27 21:17:42 +000090 %a = load float, float addrspace(1)* %gep0, align 4
91 %b = load float, float addrspace(1)* %gep1, align 4
92 %c = load float, float addrspace(1)* %gep2, align 4
Matt Arsenault8675db12014-08-29 16:01:14 +000093 %c.abs = call float @llvm.fabs.f32(float %c) #0
94 %mul = fmul float %a, %b
95 %sub = fsub float %mul, %c.abs
96 store float %sub, float addrspace(1)* %outgep, align 4
97 ret void
98}
99
Tom Stellard79243d92014-10-01 17:15:17 +0000100; FUNC-LABEL: {{^}}mad_sub_fabs_inv_f32:
Tom Stellard326d6ec2014-11-05 14:50:53 +0000101; SI: buffer_load_dword [[REGA:v[0-9]+]]
102; SI: buffer_load_dword [[REGB:v[0-9]+]]
103; SI: buffer_load_dword [[REGC:v[0-9]+]]
104; SI: v_mad_f32 [[RESULT:v[0-9]+]], -[[REGA]], [[REGB]], |[[REGC]]|
105; SI: buffer_store_dword [[RESULT]]
Matt Arsenault8675db12014-08-29 16:01:14 +0000106define void @mad_sub_fabs_inv_f32(float addrspace(1)* noalias nocapture %out, float addrspace(1)* noalias nocapture readonly %ptr) #1 {
107 %tid = tail call i32 @llvm.r600.read.tidig.x() #0
108 %tid.ext = sext i32 %tid to i64
David Blaikie79e6c742015-02-27 19:29:02 +0000109 %gep0 = getelementptr float, float addrspace(1)* %ptr, i64 %tid.ext
Matt Arsenault8675db12014-08-29 16:01:14 +0000110 %add1 = add i64 %tid.ext, 1
David Blaikie79e6c742015-02-27 19:29:02 +0000111 %gep1 = getelementptr float, float addrspace(1)* %ptr, i64 %add1
Matt Arsenault8675db12014-08-29 16:01:14 +0000112 %add2 = add i64 %tid.ext, 2
David Blaikie79e6c742015-02-27 19:29:02 +0000113 %gep2 = getelementptr float, float addrspace(1)* %ptr, i64 %add2
114 %outgep = getelementptr float, float addrspace(1)* %out, i64 %tid.ext
David Blaikiea79ac142015-02-27 21:17:42 +0000115 %a = load float, float addrspace(1)* %gep0, align 4
116 %b = load float, float addrspace(1)* %gep1, align 4
117 %c = load float, float addrspace(1)* %gep2, align 4
Matt Arsenault8675db12014-08-29 16:01:14 +0000118 %c.abs = call float @llvm.fabs.f32(float %c) #0
119 %mul = fmul float %a, %b
120 %sub = fsub float %c.abs, %mul
121 store float %sub, float addrspace(1)* %outgep, align 4
122 ret void
123}
124
Tom Stellard79243d92014-10-01 17:15:17 +0000125; FUNC-LABEL: {{^}}neg_neg_mad_f32:
Tom Stellarddb5a11f2015-07-13 15:47:57 +0000126; SI: v_mac_f32_e32 {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}
Matt Arsenault8675db12014-08-29 16:01:14 +0000127define void @neg_neg_mad_f32(float addrspace(1)* noalias nocapture %out, float addrspace(1)* noalias nocapture readonly %ptr) #1 {
128 %tid = tail call i32 @llvm.r600.read.tidig.x() #0
129 %tid.ext = sext i32 %tid to i64
David Blaikie79e6c742015-02-27 19:29:02 +0000130 %gep0 = getelementptr float, float addrspace(1)* %ptr, i64 %tid.ext
Matt Arsenault8675db12014-08-29 16:01:14 +0000131 %add1 = add i64 %tid.ext, 1
David Blaikie79e6c742015-02-27 19:29:02 +0000132 %gep1 = getelementptr float, float addrspace(1)* %ptr, i64 %add1
Matt Arsenault8675db12014-08-29 16:01:14 +0000133 %add2 = add i64 %tid.ext, 2
David Blaikie79e6c742015-02-27 19:29:02 +0000134 %gep2 = getelementptr float, float addrspace(1)* %ptr, i64 %add2
135 %outgep = getelementptr float, float addrspace(1)* %out, i64 %tid.ext
David Blaikiea79ac142015-02-27 21:17:42 +0000136 %a = load float, float addrspace(1)* %gep0, align 4
137 %b = load float, float addrspace(1)* %gep1, align 4
138 %c = load float, float addrspace(1)* %gep2, align 4
Matt Arsenault8675db12014-08-29 16:01:14 +0000139 %nega = fsub float -0.000000e+00, %a
140 %negb = fsub float -0.000000e+00, %b
141 %mul = fmul float %nega, %negb
142 %sub = fadd float %mul, %c
143 store float %sub, float addrspace(1)* %outgep, align 4
144 ret void
145}
146
Tom Stellard79243d92014-10-01 17:15:17 +0000147; FUNC-LABEL: {{^}}mad_fabs_sub_f32:
Tom Stellard326d6ec2014-11-05 14:50:53 +0000148; SI: buffer_load_dword [[REGA:v[0-9]+]]
149; SI: buffer_load_dword [[REGB:v[0-9]+]]
150; SI: buffer_load_dword [[REGC:v[0-9]+]]
151; SI: v_mad_f32 [[RESULT:v[0-9]+]], [[REGA]], |[[REGB]]|, -[[REGC]]
152; SI: buffer_store_dword [[RESULT]]
Matt Arsenault8675db12014-08-29 16:01:14 +0000153define void @mad_fabs_sub_f32(float addrspace(1)* noalias nocapture %out, float addrspace(1)* noalias nocapture readonly %ptr) #1 {
154 %tid = tail call i32 @llvm.r600.read.tidig.x() #0
155 %tid.ext = sext i32 %tid to i64
David Blaikie79e6c742015-02-27 19:29:02 +0000156 %gep0 = getelementptr float, float addrspace(1)* %ptr, i64 %tid.ext
Matt Arsenault8675db12014-08-29 16:01:14 +0000157 %add1 = add i64 %tid.ext, 1
David Blaikie79e6c742015-02-27 19:29:02 +0000158 %gep1 = getelementptr float, float addrspace(1)* %ptr, i64 %add1
Matt Arsenault8675db12014-08-29 16:01:14 +0000159 %add2 = add i64 %tid.ext, 2
David Blaikie79e6c742015-02-27 19:29:02 +0000160 %gep2 = getelementptr float, float addrspace(1)* %ptr, i64 %add2
161 %outgep = getelementptr float, float addrspace(1)* %out, i64 %tid.ext
David Blaikiea79ac142015-02-27 21:17:42 +0000162 %a = load float, float addrspace(1)* %gep0, align 4
163 %b = load float, float addrspace(1)* %gep1, align 4
164 %c = load float, float addrspace(1)* %gep2, align 4
Matt Arsenault8675db12014-08-29 16:01:14 +0000165 %b.abs = call float @llvm.fabs.f32(float %b) #0
166 %mul = fmul float %a, %b.abs
167 %sub = fsub float %mul, %c
168 store float %sub, float addrspace(1)* %outgep, align 4
169 ret void
170}
171
Tom Stellard79243d92014-10-01 17:15:17 +0000172; FUNC-LABEL: {{^}}fsub_c_fadd_a_a:
Tom Stellard326d6ec2014-11-05 14:50:53 +0000173; SI-DAG: buffer_load_dword [[R1:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}}
Matt Arsenaultfb13b222014-12-03 03:12:13 +0000174; SI-DAG: buffer_load_dword [[R2:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:4
Tom Stellarddb5a11f2015-07-13 15:47:57 +0000175; SI: v_mac_f32_e32 [[R2]], -2.0, [[R1]]
176; SI: buffer_store_dword [[R2]]
Matt Arsenault3d4233f2014-09-29 14:59:38 +0000177define void @fsub_c_fadd_a_a(float addrspace(1)* %out, float addrspace(1)* %in) {
178 %tid = call i32 @llvm.r600.read.tidig.x() nounwind readnone
David Blaikie79e6c742015-02-27 19:29:02 +0000179 %gep.0 = getelementptr float, float addrspace(1)* %out, i32 %tid
180 %gep.1 = getelementptr float, float addrspace(1)* %gep.0, i32 1
181 %gep.out = getelementptr float, float addrspace(1)* %out, i32 %tid
Matt Arsenault3d4233f2014-09-29 14:59:38 +0000182
David Blaikiea79ac142015-02-27 21:17:42 +0000183 %r1 = load float, float addrspace(1)* %gep.0
184 %r2 = load float, float addrspace(1)* %gep.1
Matt Arsenault3d4233f2014-09-29 14:59:38 +0000185
186 %add = fadd float %r1, %r1
187 %r3 = fsub float %r2, %add
188
189 store float %r3, float addrspace(1)* %gep.out
190 ret void
191}
192
Tom Stellard79243d92014-10-01 17:15:17 +0000193; FUNC-LABEL: {{^}}fsub_fadd_a_a_c:
Tom Stellard326d6ec2014-11-05 14:50:53 +0000194; SI-DAG: buffer_load_dword [[R1:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}}
Matt Arsenaultfb13b222014-12-03 03:12:13 +0000195; SI-DAG: buffer_load_dword [[R2:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:4
Tom Stellard326d6ec2014-11-05 14:50:53 +0000196; SI: v_mad_f32 [[RESULT:v[0-9]+]], 2.0, [[R1]], -[[R2]]
197; SI: buffer_store_dword [[RESULT]]
Matt Arsenault3d4233f2014-09-29 14:59:38 +0000198define void @fsub_fadd_a_a_c(float addrspace(1)* %out, float addrspace(1)* %in) {
199 %tid = call i32 @llvm.r600.read.tidig.x() nounwind readnone
David Blaikie79e6c742015-02-27 19:29:02 +0000200 %gep.0 = getelementptr float, float addrspace(1)* %out, i32 %tid
201 %gep.1 = getelementptr float, float addrspace(1)* %gep.0, i32 1
202 %gep.out = getelementptr float, float addrspace(1)* %out, i32 %tid
Matt Arsenault3d4233f2014-09-29 14:59:38 +0000203
David Blaikiea79ac142015-02-27 21:17:42 +0000204 %r1 = load float, float addrspace(1)* %gep.0
205 %r2 = load float, float addrspace(1)* %gep.1
Matt Arsenault3d4233f2014-09-29 14:59:38 +0000206
207 %add = fadd float %r1, %r1
208 %r3 = fsub float %add, %r2
209
210 store float %r3, float addrspace(1)* %gep.out
211 ret void
212}
213
Matt Arsenault8675db12014-08-29 16:01:14 +0000214attributes #0 = { nounwind readnone }
215attributes #1 = { nounwind }