1 ; RUN: llc < %s -O3 -mtriple=arm64-apple-ios -enable-unsafe-fp-math -mattr=+fullfp16 | FileCheck %s
2 ; RUN: llc < %s -O3 -mtriple=arm64-apple-ios -fp-contract=fast -mattr=+fullfp16 | FileCheck %s
4 define void @foo_2d(ptr %src) {
6 %arrayidx1 = getelementptr inbounds double, ptr %src, i64 5
7 %arrayidx2 = getelementptr inbounds double, ptr %src, i64 11
10 ; CHECK-LABEL: %for.body
11 ; CHECK: fmls.2d {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}
12 ; CHECK: fmls.2d {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}[0]
13 ; CHECK: fmsub {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}, {{d[0-9]+}}
14 for.body: ; preds = %for.body, %entry
15 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
16 %indvars.iv.next = sub nuw nsw i64 %indvars.iv, 1
17 %arrayidx3 = getelementptr inbounds double, ptr %src, i64 %indvars.iv.next
18 %tmp1 = load double, ptr %arrayidx3, align 8
19 %add = fadd fast double %tmp1, %tmp1
20 %mul = fmul fast double %add, %add
21 %e1 = insertelement <2 x double> undef, double %add, i32 0
22 %e2 = insertelement <2 x double> %e1, double %add, i32 1
23 %sub2 = fsub fast <2 x double> %e2, <double 3.000000e+00, double -3.000000e+00>
24 %e3 = insertelement <2 x double> undef, double %mul, i32 0
25 %e4 = insertelement <2 x double> %e3, double %mul, i32 1
26 %mul2 = fmul fast <2 x double> %sub2,<double 3.000000e+00, double -3.000000e+00>
27 %e5 = insertelement <2 x double> undef, double %add, i32 0
28 %e6 = insertelement <2 x double> %e5, double %add, i32 1
29 %sub3 = fsub fast <2 x double> <double 3.000000e+00, double -3.000000e+00>, %mul2
30 %mulx = fmul fast <2 x double> %sub2, %e2
31 %subx = fsub fast <2 x double> %e4, %mulx
32 %e7 = insertelement <2 x double> undef, double %mul, i32 0
33 %e8 = insertelement <2 x double> %e7, double %mul, i32 1
34 %e9 = fmul fast <2 x double> %subx, %sub3
35 store <2 x double> %e9, ptr %arrayidx1, align 8
36 %e10 = extractelement <2 x double> %sub3, i32 0
37 %mul3 = fmul fast double %mul, %e10
38 %sub4 = fsub fast double %mul, %mul3
39 store double %sub4, ptr %arrayidx2, align 8
40 %exitcond = icmp eq i64 %indvars.iv.next, 25
41 br i1 %exitcond, label %for.end, label %for.body
43 for.end: ; preds = %for.body
46 define void @foo_2s(ptr %src) {
48 %arrayidx1 = getelementptr inbounds float, ptr %src, i64 5
49 %arrayidx2 = getelementptr inbounds float, ptr %src, i64 11
52 ; CHECK-LABEL: %for.body
53 ; CHECK: fmls.2s {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}
54 ; CHECK: fmls.2s {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}[0]
55 ; CHECK: fmsub {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}, {{s[0-9]+}}
56 for.body: ; preds = %for.body, %entry
57 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
58 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
59 %arrayidx3 = getelementptr inbounds float, ptr %src, i64 %indvars.iv.next
60 %tmp1 = load float, ptr %arrayidx3, align 8
61 %add = fadd fast float %tmp1, %tmp1
62 %mul = fmul fast float %add, %add
63 %e1 = insertelement <2 x float> undef, float %add, i32 0
64 %e2 = insertelement <2 x float> %e1, float %add, i32 1
65 %add2 = fsub fast <2 x float> %e2, <float 3.000000e+00, float -3.000000e+00>
66 %e3 = insertelement <2 x float> undef, float %mul, i32 0
67 %e4 = insertelement <2 x float> %e3, float %mul, i32 1
68 %mul2 = fmul fast <2 x float> %add2,<float 3.000000e+00, float -3.000000e+00>
69 %e5 = insertelement <2 x float> undef, float %add, i32 0
70 %e6 = insertelement <2 x float> %e5, float %add, i32 1
71 %add3 = fsub fast <2 x float> <float 3.000000e+00, float -3.000000e+00>, %mul2
72 %mulx = fmul fast <2 x float> %add2, %e2
73 %addx = fsub fast <2 x float> %e4, %mulx
74 %e7 = insertelement <2 x float> undef, float %mul, i32 0
75 %e8 = insertelement <2 x float> %e7, float %mul, i32 1
76 %e9 = fmul fast <2 x float> %addx, %add3
77 store <2 x float> %e9, ptr %arrayidx1, align 8
78 %e10 = extractelement <2 x float> %add3, i32 0
79 %mul3 = fmul fast float %mul, %e10
80 %add4 = fsub fast float %mul, %mul3
81 store float %add4, ptr %arrayidx2, align 8
82 %exitcond = icmp eq i64 %indvars.iv.next, 25
83 br i1 %exitcond, label %for.end, label %for.body
85 for.end: ; preds = %for.body
88 define void @foo_4s(ptr %src) {
90 %arrayidx1 = getelementptr inbounds float, ptr %src, i64 5
91 %arrayidx2 = getelementptr inbounds float, ptr %src, i64 11
94 ; CHECK-LABEL: %for.body
95 ; CHECK: fmls.4s {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}
96 ; CHECK: fmls.4s {{v[0-9]+}}, {{v[0-9]+}}, {{v[0-9]+}}[0]
97 for.body: ; preds = %for.body, %entry
98 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
99 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
100 %arrayidx3 = getelementptr inbounds float, ptr %src, i64 %indvars.iv.next
101 %tmp1 = load float, ptr %arrayidx3, align 8
102 %add = fadd fast float %tmp1, %tmp1
103 %mul = fmul fast float %add, %add
104 %e1 = insertelement <4 x float> undef, float %add, i32 0
105 %e2 = insertelement <4 x float> %e1, float %add, i32 1
106 %add2 = fadd fast <4 x float> %e2, <float 3.000000e+00, float -3.000000e+00, float 5.000000e+00, float 7.000000e+00>
107 %e3 = insertelement <4 x float> undef, float %mul, i32 0
108 %e4 = insertelement <4 x float> %e3, float %mul, i32 1
109 %mul2 = fmul fast <4 x float> %add2,<float 3.000000e+00, float -3.000000e+00, float 5.000000e+00, float 7.000000e+00>
110 %e5 = insertelement <4 x float> undef, float %add, i32 0
111 %e6 = insertelement <4 x float> %e5, float %add, i32 1
112 %add3 = fsub fast <4 x float> <float 3.000000e+00, float -3.000000e+00, float 5.000000e+00, float 7.000000e+00> , %mul2
113 %mulx = fmul fast <4 x float> %add2, %e2
114 %addx = fsub fast <4 x float> %e4, %mulx
115 %e7 = insertelement <4 x float> undef, float %mul, i32 0
116 %e8 = insertelement <4 x float> %e7, float %mul, i32 1
117 %e9 = fmul fast <4 x float> %addx, %add3
118 store <4 x float> %e9, ptr %arrayidx1, align 8
119 %e10 = extractelement <4 x float> %add3, i32 0
120 %mul3 = fmul fast float %mul, %e10
121 store float %mul3, ptr %arrayidx2, align 8
122 %exitcond = icmp eq i64 %indvars.iv.next, 25
123 br i1 %exitcond, label %for.end, label %for.body
125 for.end: ; preds = %for.body
129 ; CHECK-LABEL: test0:
130 ; CHECK: fnmadd h0, h0, h1, h2
131 define half @test0(half %a, half %b, half %c) {
133 %0 = fmul half %a, %b
134 %mul = fsub half -0.000000e+00, %0
135 %sub1 = fsub half %mul, %c
139 ; CHECK-LABEL: test1:
140 ; CHECK: fnmadd s0, s0, s1, s2
141 define float @test1(float %a, float %b, float %c) {
143 %0 = fmul float %a, %b
144 %mul = fsub float -0.000000e+00, %0
145 %sub1 = fsub float %mul, %c
149 ; CHECK-LABEL: test2:
150 ; CHECK: fnmadd d0, d0, d1, d2
151 define double @test2(double %a, double %b, double %c) {
153 %0 = fmul double %a, %b
154 %mul = fsub double -0.000000e+00, %0
155 %sub1 = fsub double %mul, %c
159 ; CHECK-LABEL: test3:
160 ; CHECK: fnmadd h0, h0, h1, h2
161 define half @test3(half %0, half %1, half %2) {
162 %4 = fneg fast half %0
163 %5 = fmul fast half %4, %1
164 %6 = fsub fast half %5, %2
168 ; CHECK-LABEL: test4:
169 ; CHECK: fnmadd s0, s0, s1, s2
170 define float @test4(float %0, float %1, float %2) {
171 %4 = fneg fast float %0
172 %5 = fmul fast float %4, %1
173 %6 = fsub fast float %5, %2
177 ; CHECK-LABEL: test5:
178 ; CHECK: fnmadd d0, d0, d1, d2
179 define double @test5(double %0, double %1, double %2) {
180 %4 = fneg fast double %0
181 %5 = fmul fast double %4, %1
182 %6 = fsub fast double %5, %2