1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=aarch64-none-linux-gnu -verify-machineinstrs | FileCheck %s
4 define double @test1(double %a, double %b) {
7 ; CHECK-NEXT: fadd d1, d1, d1
8 ; CHECK-NEXT: fsub d0, d0, d1
10 %mul = fmul double %b, -2.000000e+00
11 %add1 = fadd double %a, %mul
15 ; DAGCombine will canonicalize 'a - 2.0*b' to 'a + -2.0*b'
17 define double @test2(double %a, double %b) {
20 ; CHECK-NEXT: fadd d1, d1, d1
21 ; CHECK-NEXT: fsub d0, d0, d1
23 %mul = fmul double %b, 2.000000e+00
24 %add1 = fsub double %a, %mul
28 define double @test3(double %a, double %b, double %c) {
31 ; CHECK-NEXT: fmul d0, d0, d1
32 ; CHECK-NEXT: fadd d1, d2, d2
33 ; CHECK-NEXT: fsub d0, d0, d1
35 %mul = fmul double %a, %b
36 %mul1 = fmul double %c, 2.000000e+00
37 %sub = fsub double %mul, %mul1
41 define double @test4(double %a, double %b, double %c) {
44 ; CHECK-NEXT: fmul d0, d0, d1
45 ; CHECK-NEXT: fadd d1, d2, d2
46 ; CHECK-NEXT: fsub d0, d0, d1
48 %mul = fmul double %a, %b
49 %mul1 = fmul double %c, -2.000000e+00
50 %add2 = fadd double %mul, %mul1
54 define <4 x float> @fmulnegtwo_vec(<4 x float> %a, <4 x float> %b) {
55 ; CHECK-LABEL: fmulnegtwo_vec:
57 ; CHECK-NEXT: fadd v1.4s, v1.4s, v1.4s
58 ; CHECK-NEXT: fsub v0.4s, v0.4s, v1.4s
60 %mul = fmul <4 x float> %b, <float -2.0, float -2.0, float -2.0, float -2.0>
61 %add = fadd <4 x float> %a, %mul
65 define <4 x float> @fmulnegtwo_vec_commute(<4 x float> %a, <4 x float> %b) {
66 ; CHECK-LABEL: fmulnegtwo_vec_commute:
68 ; CHECK-NEXT: fadd v1.4s, v1.4s, v1.4s
69 ; CHECK-NEXT: fsub v0.4s, v0.4s, v1.4s
71 %mul = fmul <4 x float> %b, <float -2.0, float -2.0, float -2.0, float -2.0>
72 %add = fadd <4 x float> %mul, %a
76 define <4 x float> @fmulnegtwo_vec_undefs(<4 x float> %a, <4 x float> %b) {
77 ; CHECK-LABEL: fmulnegtwo_vec_undefs:
79 ; CHECK-NEXT: fadd v1.4s, v1.4s, v1.4s
80 ; CHECK-NEXT: fsub v0.4s, v0.4s, v1.4s
82 %mul = fmul <4 x float> %b, <float undef, float -2.0, float undef, float -2.0>
83 %add = fadd <4 x float> %a, %mul
87 define <4 x float> @fmulnegtwo_vec_commute_undefs(<4 x float> %a, <4 x float> %b) {
88 ; CHECK-LABEL: fmulnegtwo_vec_commute_undefs:
90 ; CHECK-NEXT: fadd v1.4s, v1.4s, v1.4s
91 ; CHECK-NEXT: fsub v0.4s, v0.4s, v1.4s
93 %mul = fmul <4 x float> %b, <float -2.0, float undef, float -2.0, float -2.0>
94 %add = fadd <4 x float> %mul, %a
98 define <4 x float> @test6(<4 x float> %a, <4 x float> %b) {
101 ; CHECK-NEXT: fadd v1.4s, v1.4s, v1.4s
102 ; CHECK-NEXT: fsub v0.4s, v0.4s, v1.4s
104 %mul = fmul <4 x float> %b, <float 2.0, float 2.0, float 2.0, float 2.0>
105 %add = fsub <4 x float> %a, %mul
109 ; Don't fold (fadd A, (fmul B, -2.0)) -> (fsub A, (fadd B, B)) if the fmul has
112 define double @test7(double %a, double %b) nounwind {
113 ; CHECK-LABEL: test7:
115 ; CHECK-NEXT: str d8, [sp, #-16]! // 8-byte Folded Spill
116 ; CHECK-NEXT: fmov d2, #-2.00000000
117 ; CHECK-NEXT: fmul d1, d1, d2
118 ; CHECK-NEXT: fadd d8, d0, d1
119 ; CHECK-NEXT: mov v0.16b, v1.16b
120 ; CHECK-NEXT: str x30, [sp, #8] // 8-byte Folded Spill
122 ; CHECK-NEXT: ldr x30, [sp, #8] // 8-byte Folded Reload
123 ; CHECK-NEXT: mov v0.16b, v8.16b
124 ; CHECK-NEXT: ldr d8, [sp], #16 // 8-byte Folded Reload
126 %mul = fmul double %b, -2.000000e+00
127 %add1 = fadd double %a, %mul
128 call void @use(double %mul)
132 define float @fadd_const_multiuse_fmf(float %x) {
133 ; CHECK-LABEL: fadd_const_multiuse_fmf:
135 ; CHECK-DAG: mov [[W59:w[0-9]+]], #1114374144
136 ; CHECK-DAG: mov [[W42:w[0-9]+]], #1109917696
137 ; CHECK-DAG: fmov [[FP59:s[0-9]+]], [[W59]]
138 ; CHECK-DAG: fmov [[FP42:s[0-9]+]], [[W42]]
139 ; CHECK-NEXT: fadd [[TMP1:s[0-9]+]], s0, [[FP42]]
140 ; CHECK-NEXT: fadd [[TMP2:s[0-9]+]], s0, [[FP59]]
141 ; CHECK-NEXT: fadd s0, [[TMP1]], [[TMP2]]
143 %a1 = fadd float %x, 42.0
144 %a2 = fadd nsz reassoc float %a1, 17.0
145 %a3 = fadd float %a1, %a2
149 ; DAGCombiner transforms this into: (x + 17.0) + (x + 59.0).
150 define float @fadd_const_multiuse_attr(float %x) {
151 ; CHECK-LABEL: fadd_const_multiuse_attr:
153 ; CHECK-DAG: mov [[W17:w[0-9]+]], #1109917696
154 ; CHECK-DAG: mov [[W59:w[0-9]+]], #1114374144
155 ; CHECK-NEXT: fmov [[FP17:s[0-9]+]], [[W17]]
156 ; CHECK-NEXT: fmov [[FP59:s[0-9]+]], [[W59]]
157 ; CHECK-NEXT: fadd [[TMP1:s[0-9]+]], s0, [[FP17]]
158 ; CHECK-NEXT: fadd [[TMP2:s[0-9]+]], s0, [[FP59]]
159 ; CHECK-NEXT: fadd s0, [[TMP1]], [[TMP2]]
161 %a1 = fadd fast float %x, 42.0
162 %a2 = fadd fast float %a1, 17.0
163 %a3 = fadd fast float %a1, %a2
167 ; PR32939 - https://bugs.llvm.org/show_bug.cgi?id=32939
169 define double @fmul2_negated(double %a, double %b, double %c) {
170 ; CHECK-LABEL: fmul2_negated:
172 ; CHECK-NEXT: fadd d1, d1, d1
173 ; CHECK-NEXT: fmul d1, d1, d2
174 ; CHECK-NEXT: fsub d0, d0, d1
176 %mul = fmul double %b, 2.0
177 %mul1 = fmul double %mul, %c
178 %sub = fsub double %a, %mul1
182 define <2 x double> @fmul2_negated_vec(<2 x double> %a, <2 x double> %b, <2 x double> %c) {
183 ; CHECK-LABEL: fmul2_negated_vec:
185 ; CHECK-NEXT: fadd v1.2d, v1.2d, v1.2d
186 ; CHECK-NEXT: fmul v1.2d, v1.2d, v2.2d
187 ; CHECK-NEXT: fsub v0.2d, v0.2d, v1.2d
189 %mul = fmul <2 x double> %b, <double 2.0, double 2.0>
190 %mul1 = fmul <2 x double> %mul, %c
191 %sub = fsub <2 x double> %a, %mul1
192 ret <2 x double> %sub
195 declare void @use(double)