1 ; RUN: llc -mtriple=x86_64-unknown-unknown -march=x86-64 < %s | FileCheck %s
3 ; CHECK-LABEL: fmul2_f32:
4 ; CHECK: addss %xmm0, %xmm0
5 define float @fmul2_f32(float %x) {
6 %y = fmul float %x, 2.0
10 ; fmul 2.0, x -> fadd x, x for vectors.
12 ; CHECK-LABEL: fmul2_v4f32:
13 ; CHECK: addps %xmm0, %xmm0
15 define <4 x float> @fmul2_v4f32(<4 x float> %x) {
16 %y = fmul <4 x float> %x, <float 2.0, float 2.0, float 2.0, float 2.0>
20 ; CHECK-LABEL: constant_fold_fmul_v4f32:
23 define <4 x float> @constant_fold_fmul_v4f32(<4 x float> %x) {
24 %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>
28 ; CHECK-LABEL: fmul0_v4f32:
29 ; CHECK: xorps %xmm0, %xmm0
31 define <4 x float> @fmul0_v4f32(<4 x float> %x) #0 {
32 %y = fmul <4 x float> %x, <float 0.0, float 0.0, float 0.0, float 0.0>
36 ; CHECK-LABEL: fmul_c2_c4_v4f32:
41 define <4 x float> @fmul_c2_c4_v4f32(<4 x float> %x) #0 {
42 %y = fmul <4 x float> %x, <float 2.0, float 2.0, float 2.0, float 2.0>
43 %z = fmul <4 x float> %y, <float 4.0, float 4.0, float 4.0, float 4.0>
47 ; CHECK-LABEL: fmul_c3_c4_v4f32:
52 define <4 x float> @fmul_c3_c4_v4f32(<4 x float> %x) #0 {
53 %y = fmul <4 x float> %x, <float 3.0, float 3.0, float 3.0, float 3.0>
54 %z = fmul <4 x float> %y, <float 4.0, float 4.0, float 4.0, float 4.0>
58 ; We should be able to pre-multiply the two constant vectors.
59 ; CHECK: float 5.000000e+00
60 ; CHECK: float 1.200000e+01
61 ; CHECK: float 2.100000e+01
62 ; CHECK: float 3.200000e+01
63 ; CHECK-LABEL: fmul_v4f32_two_consts_no_splat:
67 define <4 x float> @fmul_v4f32_two_consts_no_splat(<4 x float> %x) #0 {
68 %y = fmul <4 x float> %x, <float 1.0, float 2.0, float 3.0, float 4.0>
69 %z = fmul <4 x float> %y, <float 5.0, float 6.0, float 7.0, float 8.0>
73 ; Same as above, but reverse operands to make sure non-canonical form is also handled.
74 ; CHECK: float 5.000000e+00
75 ; CHECK: float 1.200000e+01
76 ; CHECK: float 2.100000e+01
77 ; CHECK: float 3.200000e+01
78 ; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_non_canonical:
82 define <4 x float> @fmul_v4f32_two_consts_no_splat_non_canonical(<4 x float> %x) #0 {
83 %y = fmul <4 x float> <float 1.0, float 2.0, float 3.0, float 4.0>, %x
84 %z = fmul <4 x float> <float 5.0, float 6.0, float 7.0, float 8.0>, %y
88 ; More than one use of a constant multiply should not inhibit the optimization.
89 ; Instead of a chain of 2 dependent mults, this test will have 2 independent mults.
90 ; CHECK: float 6.000000e+00
91 ; CHECK: float 1.400000e+01
92 ; CHECK: float 2.400000e+01
93 ; CHECK: float 3.600000e+01
94 ; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_multiple_use:
97 define <4 x float> @fmul_v4f32_two_consts_no_splat_multiple_use(<4 x float> %x) #0 {
98 %y = fmul <4 x float> %x, <float 1.0, float 2.0, float 3.0, float 4.0>
99 %z = fmul <4 x float> %y, <float 5.0, float 6.0, float 7.0, float 8.0>
100 %a = fadd <4 x float> %y, %z
104 ; PR22698 - http://llvm.org/bugs/show_bug.cgi?id=22698
105 ; Make sure that we don't infinite loop swapping constants back and forth.
107 define <4 x float> @PR22698_splats(<4 x float> %a) #0 {
108 %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>
109 %mul2 = fmul fast <4 x float> <float 4.0, float 4.0, float 4.0, float 4.0>, %mul1
110 %mul3 = fmul fast <4 x float> %a, %mul2
111 ret <4 x float> %mul3
113 ; CHECK: float 2.400000e+01
114 ; CHECK: float 2.400000e+01
115 ; CHECK: float 2.400000e+01
116 ; CHECK: float 2.400000e+01
117 ; CHECK-LABEL: PR22698_splats:
122 ; Same as above, but verify that non-splat vectors are handled correctly too.
123 define <4 x float> @PR22698_no_splats(<4 x float> %a) #0 {
124 %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>
125 %mul2 = fmul fast <4 x float> <float 9.0, float 10.0, float 11.0, float 12.0>, %mul1
126 %mul3 = fmul fast <4 x float> %a, %mul2
127 ret <4 x float> %mul3
129 ; CHECK: float 4.500000e+01
130 ; CHECK: float 1.200000e+02
131 ; CHECK: float 2.310000e+02
132 ; CHECK: float 3.840000e+02
133 ; CHECK-LABEL: PR22698_no_splats:
138 ; CHECK-LABEL: fmul_c2_c4_f32:
143 define float @fmul_c2_c4_f32(float %x) #0 {
144 %y = fmul float %x, 2.0
145 %z = fmul float %y, 4.0
149 ; CHECK-LABEL: fmul_c3_c4_f32:
154 define float @fmul_c3_c4_f32(float %x) #0 {
155 %y = fmul float %x, 3.0
156 %z = fmul float %y, 4.0
160 ; CHECK-LABEL: fmul_fneg_fneg_f32:
161 ; CHECK: mulss %xmm1, %xmm0
163 define float @fmul_fneg_fneg_f32(float %x, float %y) {
164 %x.neg = fsub float -0.0, %x
165 %y.neg = fsub float -0.0, %y
166 %mul = fmul float %x.neg, %y.neg
169 ; CHECK-LABEL: fmul_fneg_fneg_v4f32:
170 ; CHECK: mulps {{%xmm1|\(%rdx\)}}, %xmm0
172 define <4 x float> @fmul_fneg_fneg_v4f32(<4 x float> %x, <4 x float> %y) {
173 %x.neg = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %x
174 %y.neg = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %y
175 %mul = fmul <4 x float> %x.neg, %y.neg
179 attributes #0 = { "less-precise-fpmad"="true" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "unsafe-fp-math"="true" }