xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/fp16-ops.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // REQUIRES: arm-registered-target
2*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -emit-llvm -o - -triple arm-none-linux-gnueabi %s | FileCheck %s
3*f4a2713aSLionel Sambuc typedef unsigned cond_t;
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc volatile cond_t test;
6*f4a2713aSLionel Sambuc volatile __fp16 h0 = 0.0, h1 = 1.0, h2;
7*f4a2713aSLionel Sambuc volatile float f0, f1, f2;
8*f4a2713aSLionel Sambuc 
9*f4a2713aSLionel Sambuc void foo(void) {
10*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @foo()
11*f4a2713aSLionel Sambuc 
12*f4a2713aSLionel Sambuc   // Check unary ops
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
15*f4a2713aSLionel Sambuc   // CHECK fptoi float
16*f4a2713aSLionel Sambuc   test = (h0);
17*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
18*f4a2713aSLionel Sambuc   // CHECK: fcmp une float
19*f4a2713aSLionel Sambuc   test = (!h1);
20*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
21*f4a2713aSLionel Sambuc   // CHECK: fsub float
22*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
23*f4a2713aSLionel Sambuc   h1 = -h1;
24*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
25*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
26*f4a2713aSLionel Sambuc   h1 = +h1;
27*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
28*f4a2713aSLionel Sambuc   // CHECK: fadd float
29*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
30*f4a2713aSLionel Sambuc   h1++;
31*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
32*f4a2713aSLionel Sambuc   // CHECK: fadd float
33*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
34*f4a2713aSLionel Sambuc   ++h1;
35*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
36*f4a2713aSLionel Sambuc   // CHECK: fadd float
37*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
38*f4a2713aSLionel Sambuc   --h1;
39*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
40*f4a2713aSLionel Sambuc   // CHECK: fadd float
41*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
42*f4a2713aSLionel Sambuc   h1--;
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc   // Check binary ops with various operands
45*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
46*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
47*f4a2713aSLionel Sambuc   // CHECK: fmul float
48*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
49*f4a2713aSLionel Sambuc   h1 = h0 * h2;
50*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
51*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
52*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
53*f4a2713aSLionel Sambuc   // CHECK: fmul float
54*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
55*f4a2713aSLionel Sambuc   h1 = h0 * (__fp16) -2.0;
56*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
57*f4a2713aSLionel Sambuc   // CHECK: fmul float
58*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
59*f4a2713aSLionel Sambuc   h1 = h0 * f2;
60*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
61*f4a2713aSLionel Sambuc   // CHECK: fmul float
62*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
63*f4a2713aSLionel Sambuc   h1 = f0 * h2;
64*f4a2713aSLionel Sambuc 
65*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
66*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
67*f4a2713aSLionel Sambuc   // CHECK: fdiv float
68*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
69*f4a2713aSLionel Sambuc   h1 = (h0 / h2);
70*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
71*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
72*f4a2713aSLionel Sambuc   // CHECK: fdiv float
73*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
74*f4a2713aSLionel Sambuc   h1 = (h0 / (__fp16) -2.0);
75*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
76*f4a2713aSLionel Sambuc   // CHECK: fdiv float
77*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
78*f4a2713aSLionel Sambuc   h1 = (h0 / f2);
79*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
80*f4a2713aSLionel Sambuc   // CHECK: fdiv float
81*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
82*f4a2713aSLionel Sambuc   h1 = (f0 / h2);
83*f4a2713aSLionel Sambuc 
84*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
85*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
86*f4a2713aSLionel Sambuc   // CHECK: fadd float
87*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
88*f4a2713aSLionel Sambuc   h1 = (h2 + h0);
89*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
90*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
91*f4a2713aSLionel Sambuc   // CHECK: fadd float
92*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
93*f4a2713aSLionel Sambuc   h1 = ((__fp16)-2.0 + h0);
94*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
95*f4a2713aSLionel Sambuc   // CHECK: fadd float
96*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
97*f4a2713aSLionel Sambuc   h1 = (h2 + f0);
98*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
99*f4a2713aSLionel Sambuc   // CHECK: fadd float
100*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
101*f4a2713aSLionel Sambuc   h1 = (f2 + h0);
102*f4a2713aSLionel Sambuc 
103*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
104*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
105*f4a2713aSLionel Sambuc   // CHECK: fsub float
106*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
107*f4a2713aSLionel Sambuc   h1 = (h2 - h0);
108*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
109*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
110*f4a2713aSLionel Sambuc   // CHECK: fsub float
111*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
112*f4a2713aSLionel Sambuc   h1 = ((__fp16)-2.0 - h0);
113*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
114*f4a2713aSLionel Sambuc   // CHECK: fsub float
115*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
116*f4a2713aSLionel Sambuc   h1 = (h2 - f0);
117*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
118*f4a2713aSLionel Sambuc   // CHECK: fsub float
119*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
120*f4a2713aSLionel Sambuc   h1 = (f2 - h0);
121*f4a2713aSLionel Sambuc 
122*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
123*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
124*f4a2713aSLionel Sambuc   // CHECK: fcmp olt
125*f4a2713aSLionel Sambuc   test = (h2 < h0);
126*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
127*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
128*f4a2713aSLionel Sambuc   // CHECK: fcmp olt
129*f4a2713aSLionel Sambuc   test = (h2 < (__fp16)42.0);
130*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
131*f4a2713aSLionel Sambuc   // CHECK: fcmp olt
132*f4a2713aSLionel Sambuc   test = (h2 < f0);
133*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
134*f4a2713aSLionel Sambuc   // CHECK: fcmp olt
135*f4a2713aSLionel Sambuc   test = (f2 < h0);
136*f4a2713aSLionel Sambuc 
137*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
138*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
139*f4a2713aSLionel Sambuc   // CHECK: fcmp ogt
140*f4a2713aSLionel Sambuc   test = (h0 > h2);
141*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
142*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
143*f4a2713aSLionel Sambuc   // CHECK: fcmp ogt
144*f4a2713aSLionel Sambuc   test = ((__fp16)42.0 > h2);
145*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
146*f4a2713aSLionel Sambuc   // CHECK: fcmp ogt
147*f4a2713aSLionel Sambuc   test = (h0 > f2);
148*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
149*f4a2713aSLionel Sambuc   // CHECK: fcmp ogt
150*f4a2713aSLionel Sambuc   test = (f0 > h2);
151*f4a2713aSLionel Sambuc 
152*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
153*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
154*f4a2713aSLionel Sambuc   // CHECK: fcmp ole
155*f4a2713aSLionel Sambuc   test = (h2 <= h0);
156*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
157*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
158*f4a2713aSLionel Sambuc   // CHECK: fcmp ole
159*f4a2713aSLionel Sambuc   test = (h2 <= (__fp16)42.0);
160*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
161*f4a2713aSLionel Sambuc   // CHECK: fcmp ole
162*f4a2713aSLionel Sambuc   test = (h2 <= f0);
163*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
164*f4a2713aSLionel Sambuc   // CHECK: fcmp ole
165*f4a2713aSLionel Sambuc   test = (f2 <= h0);
166*f4a2713aSLionel Sambuc 
167*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
168*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
169*f4a2713aSLionel Sambuc   // CHECK: fcmp oge
170*f4a2713aSLionel Sambuc   test = (h0 >= h2);
171*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
172*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
173*f4a2713aSLionel Sambuc   // CHECK: fcmp oge
174*f4a2713aSLionel Sambuc   test = (h0 >= (__fp16)-2.0);
175*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
176*f4a2713aSLionel Sambuc   // CHECK: fcmp oge
177*f4a2713aSLionel Sambuc   test = (h0 >= f2);
178*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
179*f4a2713aSLionel Sambuc   // CHECK: fcmp oge
180*f4a2713aSLionel Sambuc   test = (f0 >= h2);
181*f4a2713aSLionel Sambuc 
182*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
183*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
184*f4a2713aSLionel Sambuc   // CHECK: fcmp oeq
185*f4a2713aSLionel Sambuc   test = (h1 == h2);
186*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
187*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
188*f4a2713aSLionel Sambuc   // CHECK: fcmp oeq
189*f4a2713aSLionel Sambuc   test = (h1 == (__fp16)1.0);
190*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
191*f4a2713aSLionel Sambuc   // CHECK: fcmp oeq
192*f4a2713aSLionel Sambuc   test = (h1 == f1);
193*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
194*f4a2713aSLionel Sambuc   // CHECK: fcmp oeq
195*f4a2713aSLionel Sambuc   test = (f1 == h1);
196*f4a2713aSLionel Sambuc 
197*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
198*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
199*f4a2713aSLionel Sambuc   // CHECK: fcmp une
200*f4a2713aSLionel Sambuc   test = (h1 != h2);
201*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
202*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
203*f4a2713aSLionel Sambuc   // CHECK: fcmp une
204*f4a2713aSLionel Sambuc   test = (h1 != (__fp16)1.0);
205*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
206*f4a2713aSLionel Sambuc   // CHECK: fcmp une
207*f4a2713aSLionel Sambuc   test = (h1 != f1);
208*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
209*f4a2713aSLionel Sambuc   // CHECK: fcmp une
210*f4a2713aSLionel Sambuc   test = (f1 != h1);
211*f4a2713aSLionel Sambuc 
212*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
213*f4a2713aSLionel Sambuc   // CHECK: fcmp une
214*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
215*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
216*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
217*f4a2713aSLionel Sambuc   h1 = (h1 ? h2 : h0);
218*f4a2713aSLionel Sambuc   // Check assignments (inc. compound)
219*f4a2713aSLionel Sambuc   h0 = h1;
220*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
221*f4a2713aSLionel Sambuc   h0 = (__fp16)-2.0;
222*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
223*f4a2713aSLionel Sambuc   h0 = f0;
224*f4a2713aSLionel Sambuc 
225*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
226*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
227*f4a2713aSLionel Sambuc   // CHECK: fadd float
228*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
229*f4a2713aSLionel Sambuc   h0 += h1;
230*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
231*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
232*f4a2713aSLionel Sambuc   // CHECK: fadd
233*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
234*f4a2713aSLionel Sambuc   h0 += (__fp16)1.0;
235*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
236*f4a2713aSLionel Sambuc   // CHECK: fadd
237*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
238*f4a2713aSLionel Sambuc   h0 += f2;
239*f4a2713aSLionel Sambuc 
240*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
241*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
242*f4a2713aSLionel Sambuc   // CHECK: fsub
243*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
244*f4a2713aSLionel Sambuc   h0 -= h1;
245*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
246*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
247*f4a2713aSLionel Sambuc   // CHECK: fsub
248*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
249*f4a2713aSLionel Sambuc   h0 -= (__fp16)1.0;
250*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
251*f4a2713aSLionel Sambuc   // CHECK: fsub
252*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
253*f4a2713aSLionel Sambuc   h0 -= f2;
254*f4a2713aSLionel Sambuc 
255*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
256*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
257*f4a2713aSLionel Sambuc   // CHECK: fmul
258*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
259*f4a2713aSLionel Sambuc   h0 *= h1;
260*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
261*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
262*f4a2713aSLionel Sambuc   // CHECK: fmul
263*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
264*f4a2713aSLionel Sambuc   h0 *= (__fp16)1.0;
265*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
266*f4a2713aSLionel Sambuc   // CHECK: fmul
267*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
268*f4a2713aSLionel Sambuc   h0 *= f2;
269*f4a2713aSLionel Sambuc 
270*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
271*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
272*f4a2713aSLionel Sambuc   // CHECK: fdiv
273*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
274*f4a2713aSLionel Sambuc   h0 /= h1;
275*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
276*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
277*f4a2713aSLionel Sambuc   // CHECK: fdiv
278*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
279*f4a2713aSLionel Sambuc   h0 /= (__fp16)1.0;
280*f4a2713aSLionel Sambuc   // CHECK: call float @llvm.convert.from.fp16
281*f4a2713aSLionel Sambuc   // CHECK: fdiv
282*f4a2713aSLionel Sambuc   // CHECK: call i16 @llvm.convert.to.fp16
283*f4a2713aSLionel Sambuc   h0 /= f2;
284*f4a2713aSLionel Sambuc }
285