Revert rGe6ccb57bb3f6b761f2310e97fd6ca99eff42f73e "[SLP] Add cost model for `llvm...
[llvm-project.git] / llvm / test / CodeGen / AMDGPU / fmad-formation-fmul-distribute-denormal-mode.ll
blob00decf3cd4f1cf5de4e2d921cbaafc91d9a3ed29
1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -march=amdgcn -mcpu=tahiti -denormal-fp-math-f32=ieee < %s | FileCheck --check-prefix=FMA %s
3 ; RUN: llc -march=amdgcn -mcpu=verde -denormal-fp-math-f32=ieee < %s | FileCheck --check-prefix=NOFUSE %s
4 ; RUN: llc -march=amdgcn -mcpu=fiji -denormal-fp-math-f32=ieee < %s | FileCheck --check-prefix=NOFUSE %s
5 ; RUN: llc -march=amdgcn -mcpu=tonga -denormal-fp-math-f32=ieee < %s | FileCheck --check-prefix=NOFUSE %s
6 ; RUN: llc -march=amdgcn -mcpu=gfx900 -denormal-fp-math-f32=ieee < %s | FileCheck --check-prefix=FMA %s
7 ; RUN: llc -march=amdgcn -mcpu=gfx1010 -denormal-fp-math-f32=ieee < %s | FileCheck --check-prefix=FMAGFX10 %s
9 ; RUN: llc -march=amdgcn -mcpu=tahiti -denormal-fp-math-f32=preserve-sign < %s | FileCheck --check-prefix=FMAD %s
10 ; RUN: llc -march=amdgcn -mcpu=verde -denormal-fp-math-f32=preserve-sign < %s | FileCheck --check-prefix=FMAD %s
11 ; RUN: llc -march=amdgcn -mcpu=fiji -denormal-fp-math-f32=preserve-sign < %s | FileCheck --check-prefix=FMAD %s
12 ; RUN: llc -march=amdgcn -mcpu=tonga -denormal-fp-math-f32=preserve-sign < %s | FileCheck --check-prefix=FMAD %s
13 ; RUN: llc -march=amdgcn -mcpu=gfx900 -denormal-fp-math-f32=preserve-sign < %s | FileCheck --check-prefix=FMAD %s
14 ; RUN: llc -march=amdgcn -mcpu=gfx1010 -denormal-fp-math-f32=preserve-sign < %s | FileCheck --check-prefix=FMADGFX10 %s
16 ; Check for incorrect fmad formation when distributing
18 define float @unsafe_fmul_fadd_distribute_fast_f32(float %arg0, float %arg1) #0 {
19 ; FMA-LABEL: unsafe_fmul_fadd_distribute_fast_f32:
20 ; FMA:       ; %bb.0:
21 ; FMA-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
22 ; FMA-NEXT:    v_fma_f32 v0, v1, v0, v0
23 ; FMA-NEXT:    s_setpc_b64 s[30:31]
25 ; NOFUSE-LABEL: unsafe_fmul_fadd_distribute_fast_f32:
26 ; NOFUSE:       ; %bb.0:
27 ; NOFUSE-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
28 ; NOFUSE-NEXT:    v_add_f32_e32 v1, 1.0, v1
29 ; NOFUSE-NEXT:    v_mul_f32_e32 v0, v0, v1
30 ; NOFUSE-NEXT:    s_setpc_b64 s[30:31]
32 ; FMAGFX10-LABEL: unsafe_fmul_fadd_distribute_fast_f32:
33 ; FMAGFX10:       ; %bb.0:
34 ; FMAGFX10-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
35 ; FMAGFX10-NEXT:    s_waitcnt_vscnt null, 0x0
36 ; FMAGFX10-NEXT:    v_fmac_f32_e32 v0, v1, v0
37 ; FMAGFX10-NEXT:    s_setpc_b64 s[30:31]
39 ; FMAD-LABEL: unsafe_fmul_fadd_distribute_fast_f32:
40 ; FMAD:       ; %bb.0:
41 ; FMAD-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
42 ; FMAD-NEXT:    v_mac_f32_e32 v0, v1, v0
43 ; FMAD-NEXT:    s_setpc_b64 s[30:31]
45 ; FMADGFX10-LABEL: unsafe_fmul_fadd_distribute_fast_f32:
46 ; FMADGFX10:       ; %bb.0:
47 ; FMADGFX10-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
48 ; FMADGFX10-NEXT:    s_waitcnt_vscnt null, 0x0
49 ; FMADGFX10-NEXT:    v_fmac_f32_e32 v0, v1, v0
50 ; FMADGFX10-NEXT:    s_setpc_b64 s[30:31]
51   %add = fadd fast float %arg1, 1.0
52   %tmp1 = fmul fast float %arg0, %add
53   ret float %tmp1
56 define float @unsafe_fmul_fsub_distribute_fast_f32(float %arg0, float %arg1) #0 {
57 ; FMA-LABEL: unsafe_fmul_fsub_distribute_fast_f32:
58 ; FMA:       ; %bb.0:
59 ; FMA-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
60 ; FMA-NEXT:    v_fma_f32 v0, -v1, v0, v0
61 ; FMA-NEXT:    s_setpc_b64 s[30:31]
63 ; NOFUSE-LABEL: unsafe_fmul_fsub_distribute_fast_f32:
64 ; NOFUSE:       ; %bb.0:
65 ; NOFUSE-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
66 ; NOFUSE-NEXT:    v_sub_f32_e32 v1, 1.0, v1
67 ; NOFUSE-NEXT:    v_mul_f32_e32 v0, v0, v1
68 ; NOFUSE-NEXT:    s_setpc_b64 s[30:31]
70 ; FMAGFX10-LABEL: unsafe_fmul_fsub_distribute_fast_f32:
71 ; FMAGFX10:       ; %bb.0:
72 ; FMAGFX10-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
73 ; FMAGFX10-NEXT:    s_waitcnt_vscnt null, 0x0
74 ; FMAGFX10-NEXT:    v_fma_f32 v0, -v1, v0, v0
75 ; FMAGFX10-NEXT:    s_setpc_b64 s[30:31]
77 ; FMAD-LABEL: unsafe_fmul_fsub_distribute_fast_f32:
78 ; FMAD:       ; %bb.0:
79 ; FMAD-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
80 ; FMAD-NEXT:    v_mad_f32 v0, -v1, v0, v0
81 ; FMAD-NEXT:    s_setpc_b64 s[30:31]
83 ; FMADGFX10-LABEL: unsafe_fmul_fsub_distribute_fast_f32:
84 ; FMADGFX10:       ; %bb.0:
85 ; FMADGFX10-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
86 ; FMADGFX10-NEXT:    s_waitcnt_vscnt null, 0x0
87 ; FMADGFX10-NEXT:    v_fma_f32 v0, -v1, v0, v0
88 ; FMADGFX10-NEXT:    s_setpc_b64 s[30:31]
89   %add = fsub fast float 1.0, %arg1
90   %tmp1 = fmul fast float %arg0, %add
91   ret float %tmp1
94 define <2 x float> @unsafe_fmul_fadd_distribute_fast_v2f32(<2 x float> %arg0, <2 x float> %arg1) #0 {
95 ; FMA-LABEL: unsafe_fmul_fadd_distribute_fast_v2f32:
96 ; FMA:       ; %bb.0:
97 ; FMA-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
98 ; FMA-NEXT:    v_fma_f32 v0, v2, v0, v0
99 ; FMA-NEXT:    v_fma_f32 v1, v3, v1, v1
100 ; FMA-NEXT:    s_setpc_b64 s[30:31]
102 ; NOFUSE-LABEL: unsafe_fmul_fadd_distribute_fast_v2f32:
103 ; NOFUSE:       ; %bb.0:
104 ; NOFUSE-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
105 ; NOFUSE-NEXT:    v_add_f32_e32 v3, 1.0, v3
106 ; NOFUSE-NEXT:    v_add_f32_e32 v2, 1.0, v2
107 ; NOFUSE-NEXT:    v_mul_f32_e32 v0, v0, v2
108 ; NOFUSE-NEXT:    v_mul_f32_e32 v1, v1, v3
109 ; NOFUSE-NEXT:    s_setpc_b64 s[30:31]
111 ; FMAGFX10-LABEL: unsafe_fmul_fadd_distribute_fast_v2f32:
112 ; FMAGFX10:       ; %bb.0:
113 ; FMAGFX10-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
114 ; FMAGFX10-NEXT:    s_waitcnt_vscnt null, 0x0
115 ; FMAGFX10-NEXT:    v_fmac_f32_e32 v0, v2, v0
116 ; FMAGFX10-NEXT:    v_fmac_f32_e32 v1, v3, v1
117 ; FMAGFX10-NEXT:    s_setpc_b64 s[30:31]
119 ; FMAD-LABEL: unsafe_fmul_fadd_distribute_fast_v2f32:
120 ; FMAD:       ; %bb.0:
121 ; FMAD-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
122 ; FMAD-NEXT:    v_mac_f32_e32 v0, v2, v0
123 ; FMAD-NEXT:    v_mac_f32_e32 v1, v3, v1
124 ; FMAD-NEXT:    s_setpc_b64 s[30:31]
126 ; FMADGFX10-LABEL: unsafe_fmul_fadd_distribute_fast_v2f32:
127 ; FMADGFX10:       ; %bb.0:
128 ; FMADGFX10-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
129 ; FMADGFX10-NEXT:    s_waitcnt_vscnt null, 0x0
130 ; FMADGFX10-NEXT:    v_fmac_f32_e32 v0, v2, v0
131 ; FMADGFX10-NEXT:    v_fmac_f32_e32 v1, v3, v1
132 ; FMADGFX10-NEXT:    s_setpc_b64 s[30:31]
133   %add = fadd fast <2 x float> %arg1, <float 1.0, float 1.0>
134   %tmp1 = fmul fast <2 x float> %arg0, %add
135   ret <2 x float> %tmp1
138 define <2 x float> @unsafe_fmul_fsub_distribute_fast_v2f32(<2 x float> %arg0, <2 x float> %arg1) #0 {
139 ; FMA-LABEL: unsafe_fmul_fsub_distribute_fast_v2f32:
140 ; FMA:       ; %bb.0:
141 ; FMA-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
142 ; FMA-NEXT:    v_fma_f32 v0, -v2, v0, v0
143 ; FMA-NEXT:    v_fma_f32 v1, -v3, v1, v1
144 ; FMA-NEXT:    s_setpc_b64 s[30:31]
146 ; NOFUSE-LABEL: unsafe_fmul_fsub_distribute_fast_v2f32:
147 ; NOFUSE:       ; %bb.0:
148 ; NOFUSE-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
149 ; NOFUSE-NEXT:    v_sub_f32_e32 v3, 1.0, v3
150 ; NOFUSE-NEXT:    v_sub_f32_e32 v2, 1.0, v2
151 ; NOFUSE-NEXT:    v_mul_f32_e32 v0, v0, v2
152 ; NOFUSE-NEXT:    v_mul_f32_e32 v1, v1, v3
153 ; NOFUSE-NEXT:    s_setpc_b64 s[30:31]
155 ; FMAGFX10-LABEL: unsafe_fmul_fsub_distribute_fast_v2f32:
156 ; FMAGFX10:       ; %bb.0:
157 ; FMAGFX10-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
158 ; FMAGFX10-NEXT:    s_waitcnt_vscnt null, 0x0
159 ; FMAGFX10-NEXT:    v_fma_f32 v0, -v2, v0, v0
160 ; FMAGFX10-NEXT:    v_fma_f32 v1, -v3, v1, v1
161 ; FMAGFX10-NEXT:    s_setpc_b64 s[30:31]
163 ; FMAD-LABEL: unsafe_fmul_fsub_distribute_fast_v2f32:
164 ; FMAD:       ; %bb.0:
165 ; FMAD-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
166 ; FMAD-NEXT:    v_mad_f32 v0, -v2, v0, v0
167 ; FMAD-NEXT:    v_mad_f32 v1, -v3, v1, v1
168 ; FMAD-NEXT:    s_setpc_b64 s[30:31]
170 ; FMADGFX10-LABEL: unsafe_fmul_fsub_distribute_fast_v2f32:
171 ; FMADGFX10:       ; %bb.0:
172 ; FMADGFX10-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
173 ; FMADGFX10-NEXT:    s_waitcnt_vscnt null, 0x0
174 ; FMADGFX10-NEXT:    v_fma_f32 v0, -v2, v0, v0
175 ; FMADGFX10-NEXT:    v_fma_f32 v1, -v3, v1, v1
176 ; FMADGFX10-NEXT:    s_setpc_b64 s[30:31]
177   %add = fsub  fast <2 x float> <float 1.0, float 1.0>, %arg1
178   %tmp1 = fmul fast <2 x float> %arg0, %add
179   ret <2 x float> %tmp1
182 define <2 x float> @unsafe_fast_fmul_fadd_distribute_post_legalize_f32(float %arg0, <2 x float> %arg1) #0 {
183 ; FMA-LABEL: unsafe_fast_fmul_fadd_distribute_post_legalize_f32:
184 ; FMA:       ; %bb.0:
185 ; FMA-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
186 ; FMA-NEXT:    v_fma_f32 v0, v0, v1, v1
187 ; FMA-NEXT:    s_setpc_b64 s[30:31]
189 ; NOFUSE-LABEL: unsafe_fast_fmul_fadd_distribute_post_legalize_f32:
190 ; NOFUSE:       ; %bb.0:
191 ; NOFUSE-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
192 ; NOFUSE-NEXT:    v_add_f32_e32 v0, 1.0, v0
193 ; NOFUSE-NEXT:    v_mul_f32_e32 v0, v1, v0
194 ; NOFUSE-NEXT:    s_setpc_b64 s[30:31]
196 ; FMAGFX10-LABEL: unsafe_fast_fmul_fadd_distribute_post_legalize_f32:
197 ; FMAGFX10:       ; %bb.0:
198 ; FMAGFX10-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
199 ; FMAGFX10-NEXT:    s_waitcnt_vscnt null, 0x0
200 ; FMAGFX10-NEXT:    v_fma_f32 v0, v0, v1, v1
201 ; FMAGFX10-NEXT:    s_setpc_b64 s[30:31]
203 ; FMAD-LABEL: unsafe_fast_fmul_fadd_distribute_post_legalize_f32:
204 ; FMAD:       ; %bb.0:
205 ; FMAD-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
206 ; FMAD-NEXT:    v_mad_f32 v0, v0, v1, v1
207 ; FMAD-NEXT:    s_setpc_b64 s[30:31]
209 ; FMADGFX10-LABEL: unsafe_fast_fmul_fadd_distribute_post_legalize_f32:
210 ; FMADGFX10:       ; %bb.0:
211 ; FMADGFX10-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
212 ; FMADGFX10-NEXT:    s_waitcnt_vscnt null, 0x0
213 ; FMADGFX10-NEXT:    v_mad_f32 v0, v0, v1, v1
214 ; FMADGFX10-NEXT:    s_setpc_b64 s[30:31]
215   %add = fadd fast float %arg0, 1.0
216   %splat = insertelement <2 x float> undef, float %add, i32 0
217   %tmp1 = fmul fast <2 x float> %arg1, %splat
218   ret <2 x float> %tmp1
221 define <2 x float> @unsafe_fast_fmul_fsub_ditribute_post_legalize(float %arg0, <2 x float> %arg1) #0 {
222 ; FMA-LABEL: unsafe_fast_fmul_fsub_ditribute_post_legalize:
223 ; FMA:       ; %bb.0:
224 ; FMA-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
225 ; FMA-NEXT:    v_fma_f32 v0, -v0, v1, v1
226 ; FMA-NEXT:    s_setpc_b64 s[30:31]
228 ; NOFUSE-LABEL: unsafe_fast_fmul_fsub_ditribute_post_legalize:
229 ; NOFUSE:       ; %bb.0:
230 ; NOFUSE-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
231 ; NOFUSE-NEXT:    v_sub_f32_e32 v0, 1.0, v0
232 ; NOFUSE-NEXT:    v_mul_f32_e32 v0, v1, v0
233 ; NOFUSE-NEXT:    s_setpc_b64 s[30:31]
235 ; FMAGFX10-LABEL: unsafe_fast_fmul_fsub_ditribute_post_legalize:
236 ; FMAGFX10:       ; %bb.0:
237 ; FMAGFX10-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
238 ; FMAGFX10-NEXT:    s_waitcnt_vscnt null, 0x0
239 ; FMAGFX10-NEXT:    v_fma_f32 v0, -v0, v1, v1
240 ; FMAGFX10-NEXT:    s_setpc_b64 s[30:31]
242 ; FMAD-LABEL: unsafe_fast_fmul_fsub_ditribute_post_legalize:
243 ; FMAD:       ; %bb.0:
244 ; FMAD-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
245 ; FMAD-NEXT:    v_mad_f32 v0, -v0, v1, v1
246 ; FMAD-NEXT:    s_setpc_b64 s[30:31]
248 ; FMADGFX10-LABEL: unsafe_fast_fmul_fsub_ditribute_post_legalize:
249 ; FMADGFX10:       ; %bb.0:
250 ; FMADGFX10-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
251 ; FMADGFX10-NEXT:    s_waitcnt_vscnt null, 0x0
252 ; FMADGFX10-NEXT:    v_mad_f32 v0, -v0, v1, v1
253 ; FMADGFX10-NEXT:    s_setpc_b64 s[30:31]
254   %sub = fsub fast float 1.0, %arg0
255   %splat = insertelement <2 x float> undef, float %sub, i32 0
256   %tmp1 = fmul fast <2 x float> %arg1, %splat
257   ret <2 x float> %tmp1
260 attributes #0 = { "no-infs-fp-math"="true" "unsafe-fp-math"="true" }