1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=x86_64-unknown-unknown < %s | FileCheck %s
4 define <4 x float> @fmul_zero_not_fast(<4 x float> %x) nounwind {
5 ; CHECK-LABEL: fmul_zero_not_fast:
7 ; CHECK-NEXT: xorps %xmm1, %xmm1
8 ; CHECK-NEXT: mulps %xmm1, %xmm0
10 %r = fmul <4 x float> %x, zeroinitializer
14 define <4 x float> @fmul_zero_nsz_nnan(<4 x float> %x) nounwind {
15 ; CHECK-LABEL: fmul_zero_nsz_nnan:
17 ; CHECK-NEXT: xorps %xmm0, %xmm0
19 %r = fmul nsz nnan <4 x float> %x, zeroinitializer
23 define <4 x float> @fmul_zero_nsz_nnan_undef(<4 x float> %x) nounwind {
24 ; CHECK-LABEL: fmul_zero_nsz_nnan_undef:
26 ; CHECK-NEXT: xorps %xmm0, %xmm0
28 %r = fmul nsz nnan <4 x float> %x, <float 0.0, float 0.0, float 0.0, float undef>
32 define float @fmul2_f32(float %x) {
33 ; CHECK-LABEL: fmul2_f32:
35 ; CHECK-NEXT: addss %xmm0, %xmm0
37 %y = fmul float %x, 2.0
41 ; fmul 2.0, x -> fadd x, x for vectors.
43 define <4 x float> @fmul2_v4f32(<4 x float> %x) {
44 ; CHECK-LABEL: fmul2_v4f32:
46 ; CHECK-NEXT: addps %xmm0, %xmm0
48 %y = fmul <4 x float> %x, <float 2.0, float 2.0, float 2.0, float 2.0>
52 define <4 x float> @fmul2_v4f32_undef(<4 x float> %x) {
53 ; CHECK-LABEL: fmul2_v4f32_undef:
55 ; CHECK-NEXT: addps %xmm0, %xmm0
57 %y = fmul <4 x float> %x, <float undef, float 2.0, float 2.0, float 2.0>
61 define <4 x float> @constant_fold_fmul_v4f32(<4 x float> %x) {
62 ; CHECK-LABEL: constant_fold_fmul_v4f32:
64 ; CHECK-NEXT: movaps {{.*#+}} xmm0 = [8.0E+0,8.0E+0,8.0E+0,8.0E+0]
66 %y = fmul <4 x float> <float 4.0, float 4.0, float 4.0, float 4.0>, <float 2.0, float 2.0, float 2.0, float 2.0>
70 define <4 x float> @constant_fold_fmul_v4f32_undef(<4 x float> %x) {
71 ; CHECK-LABEL: constant_fold_fmul_v4f32_undef:
73 ; CHECK-NEXT: movaps {{.*#+}} xmm0 = [8.0E+0,NaN,8.0E+0,NaN]
75 %y = fmul <4 x float> <float 4.0, float undef, float 4.0, float 4.0>, <float 2.0, float 2.0, float 2.0, float undef>
79 define <4 x float> @fmul0_v4f32_nsz_nnan(<4 x float> %x) #0 {
80 ; CHECK-LABEL: fmul0_v4f32_nsz_nnan:
82 ; CHECK-NEXT: xorps %xmm0, %xmm0
84 %y = fmul nnan nsz <4 x float> %x, <float 0.0, float 0.0, float 0.0, float 0.0>
88 define <4 x float> @fmul0_v4f32_undef(<4 x float> %x) #0 {
89 ; CHECK-LABEL: fmul0_v4f32_undef:
91 ; CHECK-NEXT: xorps %xmm0, %xmm0
93 %y = fmul nnan nsz <4 x float> %x, <float undef, float 0.0, float undef, float 0.0>
97 define <4 x float> @fmul_c2_c4_v4f32(<4 x float> %x) #0 {
98 ; CHECK-LABEL: fmul_c2_c4_v4f32:
100 ; CHECK-NEXT: mulps {{.*}}(%rip), %xmm0
102 %y = fmul <4 x float> %x, <float 2.0, float 2.0, float 2.0, float 2.0>
103 %z = fmul <4 x float> %y, <float 4.0, float 4.0, float 4.0, float 4.0>
107 define <4 x float> @fmul_c3_c4_v4f32(<4 x float> %x) #0 {
108 ; CHECK-LABEL: fmul_c3_c4_v4f32:
110 ; CHECK-NEXT: mulps {{.*}}(%rip), %xmm0
112 %y = fmul <4 x float> %x, <float 3.0, float 3.0, float 3.0, float 3.0>
113 %z = fmul <4 x float> %y, <float 4.0, float 4.0, float 4.0, float 4.0>
122 ; We should be able to pre-multiply the two constant vectors.
123 define <4 x float> @fmul_v4f32_two_consts_no_splat(<4 x float> %x) #0 {
124 ; CHECK-LABEL: fmul_v4f32_two_consts_no_splat:
126 ; CHECK-NEXT: mulps {{.*}}(%rip), %xmm0
128 %y = fmul <4 x float> %x, <float 1.0, float 2.0, float 3.0, float 4.0>
129 %z = fmul <4 x float> %y, <float 5.0, float 6.0, float 7.0, float 8.0>
133 ; Same as above, but reverse operands to make sure non-canonical form is also handled.
134 define <4 x float> @fmul_v4f32_two_consts_no_splat_non_canonical(<4 x float> %x) #0 {
135 ; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_non_canonical:
137 ; CHECK-NEXT: mulps {{.*}}(%rip), %xmm0
139 %y = fmul <4 x float> <float 1.0, float 2.0, float 3.0, float 4.0>, %x
140 %z = fmul <4 x float> <float 5.0, float 6.0, float 7.0, float 8.0>, %y
144 ; Node-level FMF and no function-level attributes.
146 define <4 x float> @fmul_v4f32_two_consts_no_splat_reassoc(<4 x float> %x) {
147 ; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_reassoc:
149 ; CHECK-NEXT: mulps {{.*}}(%rip), %xmm0
151 %y = fmul <4 x float> %x, <float 1.0, float 2.0, float 3.0, float 4.0>
152 %z = fmul reassoc <4 x float> %y, <float 5.0, float 6.0, float 7.0, float 8.0>
156 ; Multiplication by 2.0 is a special case because that gets converted to fadd x, x.
158 define <4 x float> @fmul_v4f32_two_consts_no_splat_reassoc_2(<4 x float> %x) {
159 ; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_reassoc_2:
161 ; CHECK-NEXT: mulps {{.*}}(%rip), %xmm0
163 %y = fadd <4 x float> %x, %x
164 %z = fmul reassoc <4 x float> %y, <float 5.0, float 6.0, float 7.0, float 8.0>
173 ; More than one use of a constant multiply should not inhibit the optimization.
174 ; Instead of a chain of 2 dependent mults, this test will have 2 independent mults.
175 define <4 x float> @fmul_v4f32_two_consts_no_splat_multiple_use(<4 x float> %x) #0 {
176 ; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_multiple_use:
178 ; CHECK-NEXT: mulps {{.*}}(%rip), %xmm0
180 %y = fmul <4 x float> %x, <float 1.0, float 2.0, float 3.0, float 4.0>
181 %z = fmul <4 x float> %y, <float 5.0, float 6.0, float 7.0, float 8.0>
182 %a = fadd <4 x float> %y, %z
186 ; PR22698 - http://llvm.org/bugs/show_bug.cgi?id=22698
187 ; Make sure that we don't infinite loop swapping constants back and forth.
194 define <4 x float> @PR22698_splats(<4 x float> %a) #0 {
195 ; CHECK-LABEL: PR22698_splats:
197 ; CHECK-NEXT: mulps {{.*}}(%rip), %xmm0
199 %mul1 = fmul fast <4 x float> <float 2.0, float 2.0, float 2.0, float 2.0>, <float 3.0, float 3.0, float 3.0, float 3.0>
200 %mul2 = fmul fast <4 x float> <float 4.0, float 4.0, float 4.0, float 4.0>, %mul1
201 %mul3 = fmul fast <4 x float> %a, %mul2
202 ret <4 x float> %mul3
205 ; Same as above, but verify that non-splat vectors are handled correctly too.
212 define <4 x float> @PR22698_no_splats(<4 x float> %a) #0 {
213 ; CHECK-LABEL: PR22698_no_splats:
215 ; CHECK-NEXT: mulps {{.*}}(%rip), %xmm0
217 %mul1 = fmul fast <4 x float> <float 1.0, float 2.0, float 3.0, float 4.0>, <float 5.0, float 6.0, float 7.0, float 8.0>
218 %mul2 = fmul fast <4 x float> <float 9.0, float 10.0, float 11.0, float 12.0>, %mul1
219 %mul3 = fmul fast <4 x float> %a, %mul2
220 ret <4 x float> %mul3
223 define float @fmul_c2_c4_f32(float %x) #0 {
224 ; CHECK-LABEL: fmul_c2_c4_f32:
226 ; CHECK-NEXT: mulss {{.*}}(%rip), %xmm0
228 %y = fmul float %x, 2.0
229 %z = fmul float %y, 4.0
233 define float @fmul_c3_c4_f32(float %x) #0 {
234 ; CHECK-LABEL: fmul_c3_c4_f32:
236 ; CHECK-NEXT: mulss {{.*}}(%rip), %xmm0
238 %y = fmul float %x, 3.0
239 %z = fmul float %y, 4.0
243 define float @fmul_fneg_fneg_f32(float %x, float %y) {
244 ; CHECK-LABEL: fmul_fneg_fneg_f32:
246 ; CHECK-NEXT: mulss %xmm1, %xmm0
248 %x.neg = fsub float -0.0, %x
249 %y.neg = fsub float -0.0, %y
250 %mul = fmul float %x.neg, %y.neg
254 define <4 x float> @fmul_fneg_fneg_v4f32(<4 x float> %x, <4 x float> %y) {
255 ; CHECK-LABEL: fmul_fneg_fneg_v4f32:
257 ; CHECK-NEXT: mulps %xmm1, %xmm0
259 %x.neg = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %x
260 %y.neg = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %y
261 %mul = fmul <4 x float> %x.neg, %y.neg
265 attributes #0 = { "less-precise-fpmad"="true" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "unsafe-fp-math"="true" }