Branch data Line data Source code
1 : : /* Constant folding for calls to built-in and internal functions.
2 : : Copyright (C) 1988-2025 Free Software Foundation, Inc.
3 : :
4 : : This file is part of GCC.
5 : :
6 : : GCC is free software; you can redistribute it and/or modify it under
7 : : the terms of the GNU General Public License as published by the Free
8 : : Software Foundation; either version 3, or (at your option) any later
9 : : version.
10 : :
11 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : : for more details.
15 : :
16 : : You should have received a copy of the GNU General Public License
17 : : along with GCC; see the file COPYING3. If not see
18 : : <http://www.gnu.org/licenses/>. */
19 : :
20 : : #include "config.h"
21 : : #include "system.h"
22 : : #include "coretypes.h"
23 : : #include "realmpfr.h"
24 : : #include "tree.h"
25 : : #include "stor-layout.h"
26 : : #include "options.h"
27 : : #include "fold-const.h"
28 : : #include "fold-const-call.h"
29 : : #include "case-cfn-macros.h"
30 : : #include "tm.h" /* For C[LT]Z_DEFINED_VALUE_AT_ZERO. */
31 : : #include "builtins.h"
32 : : #include "gimple-expr.h"
33 : : #include "tree-vector-builder.h"
34 : :
35 : : /* Functions that test for certain constant types, abstracting away the
36 : : decision about whether to check for overflow. */
37 : :
38 : : static inline bool
39 : 34510140 : integer_cst_p (tree t)
40 : : {
41 : 34510140 : return TREE_CODE (t) == INTEGER_CST && !TREE_OVERFLOW (t);
42 : : }
43 : :
44 : : static inline bool
45 : 38955810 : real_cst_p (tree t)
46 : : {
47 : 38955810 : return TREE_CODE (t) == REAL_CST && !TREE_OVERFLOW (t);
48 : : }
49 : :
50 : : static inline bool
51 : 23784753 : complex_cst_p (tree t)
52 : : {
53 : 23784753 : return TREE_CODE (t) == COMPLEX_CST;
54 : : }
55 : :
56 : : /* Return true if ARG is a size_type_node constant.
57 : : Store it in *SIZE_OUT if so. */
58 : :
59 : : static inline bool
60 : 2640362 : size_t_cst_p (tree t, unsigned HOST_WIDE_INT *size_out)
61 : : {
62 : 2640362 : if (types_compatible_p (size_type_node, TREE_TYPE (t))
63 : 2640207 : && integer_cst_p (t)
64 : 4221516 : && tree_fits_uhwi_p (t))
65 : : {
66 : 1581154 : *size_out = tree_to_uhwi (t);
67 : 1581154 : return true;
68 : : }
69 : : return false;
70 : : }
71 : :
72 : : /* RES is the result of a comparison in which < 0 means "less", 0 means
73 : : "equal" and > 0 means "more". Canonicalize it to -1, 0 or 1 and
74 : : return it in type TYPE. */
75 : :
76 : : tree
77 : 65721 : build_cmp_result (tree type, int res)
78 : : {
79 : 70407 : return build_int_cst (type, res < 0 ? -1 : res > 0 ? 1 : 0);
80 : : }
81 : :
82 : : /* M is the result of trying to constant-fold an expression (starting
83 : : with clear MPFR flags) and INEXACT says whether the result in M is
84 : : exact or inexact. Return true if M can be used as a constant-folded
85 : : result in format FORMAT, storing the value in *RESULT if so. */
86 : :
87 : : static bool
88 : 261812 : do_mpfr_ckconv (real_value *result, mpfr_srcptr m, bool inexact,
89 : : const real_format *format)
90 : : {
91 : : /* Proceed iff we get a normal number, i.e. not NaN or Inf and no
92 : : overflow/underflow occurred. If -frounding-math, proceed iff the
93 : : result of calling FUNC was exact. */
94 : 261812 : if (!mpfr_number_p (m)
95 : 246803 : || mpfr_overflow_p ()
96 : 246803 : || mpfr_underflow_p ()
97 : 505071 : || (flag_rounding_math && inexact))
98 : 18638 : return false;
99 : :
100 : 243174 : REAL_VALUE_TYPE tmp;
101 : 243174 : real_from_mpfr (&tmp, m, format, MPFR_RNDN);
102 : :
103 : : /* Proceed iff GCC's REAL_VALUE_TYPE can hold the MPFR values.
104 : : If the REAL_VALUE_TYPE is zero but the mpfr_t is not, then we
105 : : underflowed in the conversion. */
106 : 243174 : if (!real_isfinite (&tmp)
107 : 243174 : || ((tmp.cl == rvc_zero) != (mpfr_zero_p (m) != 0)))
108 : : return false;
109 : :
110 : 243174 : real_convert (result, format, &tmp);
111 : 243174 : return real_identical (result, &tmp);
112 : : }
113 : :
114 : : /* Try to evaluate:
115 : :
116 : : *RESULT = f (*ARG)
117 : :
118 : : in format FORMAT, given that FUNC is the MPFR implementation of f.
119 : : Return true on success. */
120 : :
121 : : static bool
122 : 122505 : do_mpfr_arg1 (real_value *result,
123 : : int (*func) (mpfr_ptr, mpfr_srcptr, mpfr_rnd_t),
124 : : const real_value *arg, const real_format *format)
125 : : {
126 : : /* To proceed, MPFR must exactly represent the target floating point
127 : : format, which only happens when the target base equals two. */
128 : 122505 : if (format->b != 2 || !real_isfinite (arg))
129 : 2742 : return false;
130 : :
131 : 119763 : int prec = format->p;
132 : 119763 : mpfr_rnd_t rnd = format->round_towards_zero ? MPFR_RNDZ : MPFR_RNDN;
133 : :
134 : 119763 : auto_mpfr m (prec);
135 : 119763 : mpfr_from_real (m, arg, MPFR_RNDN);
136 : 119763 : mpfr_clear_flags ();
137 : 119763 : bool inexact = func (m, m, rnd);
138 : 119763 : bool ok = do_mpfr_ckconv (result, m, inexact, format);
139 : :
140 : 119763 : return ok;
141 : 119763 : }
142 : :
143 : : /* Try to evaluate:
144 : :
145 : : *RESULT_SIN = sin (*ARG);
146 : : *RESULT_COS = cos (*ARG);
147 : :
148 : : for format FORMAT. Return true on success. */
149 : :
150 : : static bool
151 : 154 : do_mpfr_sincos (real_value *result_sin, real_value *result_cos,
152 : : const real_value *arg, const real_format *format)
153 : : {
154 : : /* To proceed, MPFR must exactly represent the target floating point
155 : : format, which only happens when the target base equals two. */
156 : 154 : if (format->b != 2 || !real_isfinite (arg))
157 : 0 : return false;
158 : :
159 : 154 : int prec = format->p;
160 : 154 : mpfr_rnd_t rnd = format->round_towards_zero ? MPFR_RNDZ : MPFR_RNDN;
161 : 154 : mpfr_t m, ms, mc;
162 : :
163 : 154 : mpfr_inits2 (prec, m, ms, mc, NULL);
164 : 154 : mpfr_from_real (m, arg, MPFR_RNDN);
165 : 154 : mpfr_clear_flags ();
166 : 154 : bool inexact = mpfr_sin_cos (ms, mc, m, rnd);
167 : 154 : bool ok = (do_mpfr_ckconv (result_sin, ms, inexact, format)
168 : 154 : && do_mpfr_ckconv (result_cos, mc, inexact, format));
169 : 154 : mpfr_clears (m, ms, mc, NULL);
170 : :
171 : 154 : return ok;
172 : : }
173 : :
174 : : /* Try to evaluate:
175 : :
176 : : *RESULT = f (*ARG0, *ARG1)
177 : :
178 : : in format FORMAT, given that FUNC is the MPFR implementation of f.
179 : : Return true on success. */
180 : :
181 : : static bool
182 : 148504 : do_mpfr_arg2 (real_value *result,
183 : : int (*func) (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t),
184 : : const real_value *arg0, const real_value *arg1,
185 : : const real_format *format)
186 : : {
187 : : /* To proceed, MPFR must exactly represent the target floating point
188 : : format, which only happens when the target base equals two. */
189 : 148504 : if (format->b != 2 || !real_isfinite (arg0) || !real_isfinite (arg1))
190 : 11040 : return false;
191 : :
192 : 137464 : int prec = format->p;
193 : 137464 : mpfr_rnd_t rnd = format->round_towards_zero ? MPFR_RNDZ : MPFR_RNDN;
194 : 137464 : mpfr_t m0, m1;
195 : :
196 : 137464 : mpfr_inits2 (prec, m0, m1, NULL);
197 : 137464 : mpfr_from_real (m0, arg0, MPFR_RNDN);
198 : 137464 : mpfr_from_real (m1, arg1, MPFR_RNDN);
199 : 137464 : mpfr_clear_flags ();
200 : 137464 : bool inexact = func (m0, m0, m1, rnd);
201 : 137464 : bool ok = do_mpfr_ckconv (result, m0, inexact, format);
202 : 137464 : mpfr_clears (m0, m1, NULL);
203 : :
204 : 137464 : return ok;
205 : : }
206 : :
207 : : /* Try to evaluate:
208 : :
209 : : *RESULT = f (ARG0, *ARG1)
210 : :
211 : : in format FORMAT, given that FUNC is the MPFR implementation of f.
212 : : Return true on success. */
213 : :
214 : : static bool
215 : 1743 : do_mpfr_arg2 (real_value *result,
216 : : int (*func) (mpfr_ptr, long, mpfr_srcptr, mpfr_rnd_t),
217 : : const wide_int_ref &arg0, const real_value *arg1,
218 : : const real_format *format)
219 : : {
220 : 1743 : if (format->b != 2 || !real_isfinite (arg1))
221 : 0 : return false;
222 : :
223 : 1743 : int prec = format->p;
224 : 1743 : mpfr_rnd_t rnd = format->round_towards_zero ? MPFR_RNDZ : MPFR_RNDN;
225 : :
226 : 1743 : auto_mpfr m (prec);
227 : 1743 : mpfr_from_real (m, arg1, MPFR_RNDN);
228 : 1743 : mpfr_clear_flags ();
229 : 1743 : bool inexact = func (m, arg0.to_shwi (), m, rnd);
230 : 1743 : bool ok = do_mpfr_ckconv (result, m, inexact, format);
231 : :
232 : 1743 : return ok;
233 : 1743 : }
234 : :
235 : : /* Try to evaluate:
236 : :
237 : : *RESULT = f (*ARG0, *ARG1, *ARG2)
238 : :
239 : : in format FORMAT, given that FUNC is the MPFR implementation of f.
240 : : Return true on success. */
241 : :
242 : : static bool
243 : 2534 : do_mpfr_arg3 (real_value *result,
244 : : int (*func) (mpfr_ptr, mpfr_srcptr, mpfr_srcptr,
245 : : mpfr_srcptr, mpfr_rnd_t),
246 : : const real_value *arg0, const real_value *arg1,
247 : : const real_value *arg2, const real_format *format)
248 : : {
249 : : /* To proceed, MPFR must exactly represent the target floating point
250 : : format, which only happens when the target base equals two. */
251 : 2534 : if (format->b != 2
252 : 2534 : || !real_isfinite (arg0)
253 : 2534 : || !real_isfinite (arg1)
254 : 5068 : || !real_isfinite (arg2))
255 : 0 : return false;
256 : :
257 : 2534 : int prec = format->p;
258 : 2534 : mpfr_rnd_t rnd = format->round_towards_zero ? MPFR_RNDZ : MPFR_RNDN;
259 : 2534 : mpfr_t m0, m1, m2;
260 : :
261 : 2534 : mpfr_inits2 (prec, m0, m1, m2, NULL);
262 : 2534 : mpfr_from_real (m0, arg0, MPFR_RNDN);
263 : 2534 : mpfr_from_real (m1, arg1, MPFR_RNDN);
264 : 2534 : mpfr_from_real (m2, arg2, MPFR_RNDN);
265 : 2534 : mpfr_clear_flags ();
266 : 2534 : bool inexact = func (m0, m0, m1, m2, rnd);
267 : 2534 : bool ok = do_mpfr_ckconv (result, m0, inexact, format);
268 : 2534 : mpfr_clears (m0, m1, m2, NULL);
269 : :
270 : 2534 : return ok;
271 : : }
272 : :
273 : : /* M is the result of trying to constant-fold an expression (starting
274 : : with clear MPFR flags) and INEXACT says whether the result in M is
275 : : exact or inexact. Return true if M can be used as a constant-folded
276 : : result in which the real and imaginary parts have format FORMAT.
277 : : Store those parts in *RESULT_REAL and *RESULT_IMAG if so. */
278 : :
279 : : static bool
280 : 38801 : do_mpc_ckconv (real_value *result_real, real_value *result_imag,
281 : : mpc_srcptr m, bool inexact, const real_format *format)
282 : : {
283 : : /* Proceed iff we get a normal number, i.e. not NaN or Inf and no
284 : : overflow/underflow occurred. If -frounding-math, proceed iff the
285 : : result of calling FUNC was exact. */
286 : 38801 : if (!mpfr_number_p (mpc_realref (m))
287 : 33261 : || !mpfr_number_p (mpc_imagref (m))
288 : 33261 : || mpfr_overflow_p ()
289 : 33261 : || mpfr_underflow_p ()
290 : 68428 : || (flag_rounding_math && inexact))
291 : 9174 : return false;
292 : :
293 : 29627 : REAL_VALUE_TYPE tmp_real, tmp_imag;
294 : 29627 : real_from_mpfr (&tmp_real, mpc_realref (m), format, MPFR_RNDN);
295 : 29627 : real_from_mpfr (&tmp_imag, mpc_imagref (m), format, MPFR_RNDN);
296 : :
297 : : /* Proceed iff GCC's REAL_VALUE_TYPE can hold the MPFR values.
298 : : If the REAL_VALUE_TYPE is zero but the mpfr_t is not, then we
299 : : underflowed in the conversion. */
300 : 29627 : if (!real_isfinite (&tmp_real)
301 : 29627 : || !real_isfinite (&tmp_imag)
302 : 29627 : || (tmp_real.cl == rvc_zero) != (mpfr_zero_p (mpc_realref (m)) != 0)
303 : 59254 : || (tmp_imag.cl == rvc_zero) != (mpfr_zero_p (mpc_imagref (m)) != 0))
304 : 0 : return false;
305 : :
306 : 29627 : real_convert (result_real, format, &tmp_real);
307 : 29627 : real_convert (result_imag, format, &tmp_imag);
308 : :
309 : 29627 : return (real_identical (result_real, &tmp_real)
310 : 29627 : && real_identical (result_imag, &tmp_imag));
311 : : }
312 : :
313 : : /* Try to evaluate:
314 : :
315 : : RESULT = f (ARG)
316 : :
317 : : in format FORMAT, given that FUNC is the mpc implementation of f.
318 : : Return true on success. Both RESULT and ARG are represented as
319 : : real and imaginary pairs. */
320 : :
321 : : static bool
322 : 13700 : do_mpc_arg1 (real_value *result_real, real_value *result_imag,
323 : : int (*func) (mpc_ptr, mpc_srcptr, mpc_rnd_t),
324 : : const real_value *arg_real, const real_value *arg_imag,
325 : : const real_format *format)
326 : : {
327 : : /* To proceed, MPFR must exactly represent the target floating point
328 : : format, which only happens when the target base equals two. */
329 : 13700 : if (format->b != 2
330 : 13700 : || !real_isfinite (arg_real)
331 : 25078 : || !real_isfinite (arg_imag))
332 : 2322 : return false;
333 : :
334 : 11378 : int prec = format->p;
335 : 11378 : mpc_rnd_t crnd = format->round_towards_zero ? MPC_RNDZZ : MPC_RNDNN;
336 : 11378 : mpc_t m;
337 : :
338 : 11378 : mpc_init2 (m, prec);
339 : 11378 : mpfr_from_real (mpc_realref (m), arg_real, MPFR_RNDN);
340 : 11378 : mpfr_from_real (mpc_imagref (m), arg_imag, MPFR_RNDN);
341 : 11378 : mpfr_clear_flags ();
342 : 11378 : bool inexact = func (m, m, crnd);
343 : 11378 : bool ok = do_mpc_ckconv (result_real, result_imag, m, inexact, format);
344 : 11378 : mpc_clear (m);
345 : :
346 : 11378 : return ok;
347 : : }
348 : :
349 : : /* Try to evaluate:
350 : :
351 : : RESULT = f (ARG0, ARG1)
352 : :
353 : : in format FORMAT, given that FUNC is the mpc implementation of f.
354 : : Return true on success. RESULT, ARG0 and ARG1 are represented as
355 : : real and imaginary pairs. */
356 : :
357 : : static bool
358 : 32067 : do_mpc_arg2 (real_value *result_real, real_value *result_imag,
359 : : int (*func)(mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t),
360 : : const real_value *arg0_real, const real_value *arg0_imag,
361 : : const real_value *arg1_real, const real_value *arg1_imag,
362 : : const real_format *format)
363 : : {
364 : 32067 : if (!real_isfinite (arg0_real)
365 : 29745 : || !real_isfinite (arg0_imag)
366 : 29745 : || !real_isfinite (arg1_real)
367 : 59490 : || !real_isfinite (arg1_imag))
368 : 4644 : return false;
369 : :
370 : 27423 : int prec = format->p;
371 : 27423 : mpc_rnd_t crnd = format->round_towards_zero ? MPC_RNDZZ : MPC_RNDNN;
372 : 27423 : mpc_t m0, m1;
373 : :
374 : 27423 : mpc_init2 (m0, prec);
375 : 27423 : mpc_init2 (m1, prec);
376 : 27423 : mpfr_from_real (mpc_realref (m0), arg0_real, MPFR_RNDN);
377 : 27423 : mpfr_from_real (mpc_imagref (m0), arg0_imag, MPFR_RNDN);
378 : 27423 : mpfr_from_real (mpc_realref (m1), arg1_real, MPFR_RNDN);
379 : 27423 : mpfr_from_real (mpc_imagref (m1), arg1_imag, MPFR_RNDN);
380 : 27423 : mpfr_clear_flags ();
381 : 27423 : bool inexact = func (m0, m0, m1, crnd);
382 : 27423 : bool ok = do_mpc_ckconv (result_real, result_imag, m0, inexact, format);
383 : 27423 : mpc_clear (m0);
384 : 27423 : mpc_clear (m1);
385 : :
386 : 27423 : return ok;
387 : : }
388 : :
389 : : /* Try to evaluate:
390 : :
391 : : *RESULT = logb (*ARG)
392 : :
393 : : in format FORMAT. Return true on success. */
394 : :
395 : : static bool
396 : 4463 : fold_const_logb (real_value *result, const real_value *arg,
397 : : const real_format *format)
398 : : {
399 : 4463 : switch (arg->cl)
400 : : {
401 : 106 : case rvc_nan:
402 : : /* If arg is +-NaN, then return it. */
403 : 106 : *result = *arg;
404 : 106 : return true;
405 : :
406 : 116 : case rvc_inf:
407 : : /* If arg is +-Inf, then return +Inf. */
408 : 116 : *result = *arg;
409 : 116 : result->sign = 0;
410 : 116 : return true;
411 : :
412 : : case rvc_zero:
413 : : /* Zero may set errno and/or raise an exception. */
414 : : return false;
415 : :
416 : 1670 : case rvc_normal:
417 : : /* For normal numbers, proceed iff radix == 2. In GCC,
418 : : normalized significands are in the range [0.5, 1.0). We
419 : : want the exponent as if they were [1.0, 2.0) so get the
420 : : exponent and subtract 1. */
421 : 1670 : if (format->b == 2)
422 : : {
423 : 1670 : real_from_integer (result, format, REAL_EXP (arg) - 1, SIGNED);
424 : 1670 : return true;
425 : : }
426 : : return false;
427 : : }
428 : : }
429 : :
430 : : /* Try to evaluate:
431 : :
432 : : *RESULT = significand (*ARG)
433 : :
434 : : in format FORMAT. Return true on success. */
435 : :
436 : : static bool
437 : 960 : fold_const_significand (real_value *result, const real_value *arg,
438 : : const real_format *format)
439 : : {
440 : 0 : switch (arg->cl)
441 : : {
442 : 288 : case rvc_zero:
443 : 288 : case rvc_nan:
444 : 288 : case rvc_inf:
445 : : /* If arg is +-0, +-Inf or +-NaN, then return it. */
446 : 288 : *result = *arg;
447 : 288 : return true;
448 : :
449 : 672 : case rvc_normal:
450 : : /* For normal numbers, proceed iff radix == 2. */
451 : 672 : if (format->b == 2)
452 : : {
453 : 672 : *result = *arg;
454 : : /* In GCC, normalized significands are in the range [0.5, 1.0).
455 : : We want them to be [1.0, 2.0) so set the exponent to 1. */
456 : 672 : SET_REAL_EXP (result, 1);
457 : 672 : return true;
458 : : }
459 : : return false;
460 : : }
461 : : }
462 : :
463 : : /* Try to evaluate:
464 : :
465 : : *RESULT = f (*ARG)
466 : :
467 : : where FORMAT is the format of *ARG and PRECISION is the number of
468 : : significant bits in the result. Return true on success. */
469 : :
470 : : static bool
471 : 1640 : fold_const_conversion (wide_int *result,
472 : : void (*fn) (real_value *, format_helper,
473 : : const real_value *),
474 : : const real_value *arg, unsigned int precision,
475 : : const real_format *format)
476 : : {
477 : 1640 : if (!real_isfinite (arg))
478 : : return false;
479 : :
480 : 1640 : real_value rounded;
481 : 1640 : fn (&rounded, format, arg);
482 : :
483 : 1640 : bool fail = false;
484 : 1640 : *result = real_to_integer (&rounded, &fail, precision);
485 : 1640 : return !fail;
486 : : }
487 : :
488 : : /* Try to evaluate:
489 : :
490 : : *RESULT = pow (*ARG0, *ARG1)
491 : :
492 : : in format FORMAT. Return true on success. */
493 : :
494 : : static bool
495 : 131528 : fold_const_pow (real_value *result, const real_value *arg0,
496 : : const real_value *arg1, const real_format *format)
497 : : {
498 : 131528 : if (do_mpfr_arg2 (result, mpfr_pow, arg0, arg1, format))
499 : : return true;
500 : :
501 : : /* Check for an integer exponent. */
502 : 10271 : REAL_VALUE_TYPE cint1;
503 : 10271 : HOST_WIDE_INT n1 = real_to_integer (arg1);
504 : 10271 : real_from_integer (&cint1, VOIDmode, n1, SIGNED);
505 : : /* Attempt to evaluate pow at compile-time, unless this should
506 : : raise an exception. */
507 : 10271 : if (real_identical (arg1, &cint1)
508 : 10271 : && (n1 > 0
509 : 774 : || (!flag_trapping_math && !flag_errno_math)
510 : 774 : || !real_equal (arg0, &dconst0)))
511 : : {
512 : 1548 : bool inexact = real_powi (result, format, arg0, n1);
513 : : /* Avoid the folding if flag_signaling_nans is on. */
514 : 1548 : if (flag_unsafe_math_optimizations
515 : 1548 : || (!inexact
516 : 0 : && !(flag_signaling_nans
517 : 0 : && REAL_VALUE_ISSIGNALING_NAN (*arg0))))
518 : 0 : return true;
519 : : }
520 : :
521 : : return false;
522 : : }
523 : :
524 : : /* Try to evaluate:
525 : :
526 : : *RESULT = nextafter (*ARG0, *ARG1)
527 : :
528 : : or
529 : :
530 : : *RESULT = nexttoward (*ARG0, *ARG1)
531 : :
532 : : in format FORMAT. Return true on success. */
533 : :
534 : : static bool
535 : 15625 : fold_const_nextafter (real_value *result, const real_value *arg0,
536 : : const real_value *arg1, const real_format *format)
537 : : {
538 : 15625 : if (REAL_VALUE_ISSIGNALING_NAN (*arg0)
539 : 15625 : || REAL_VALUE_ISSIGNALING_NAN (*arg1))
540 : 0 : return false;
541 : :
542 : : /* Don't handle composite modes, nor decimal, nor modes without
543 : : inf or denorm at least for now. */
544 : 15625 : if (format->pnan < format->p
545 : 15625 : || format->b == 10
546 : 15625 : || !format->has_inf
547 : 15625 : || !format->has_denorm)
548 : : return false;
549 : :
550 : 24509 : if (real_nextafter (result, format, arg0, arg1)
551 : : /* If raising underflow or overflow and setting errno to ERANGE,
552 : : fail if we care about those side-effects. */
553 : 15625 : && (flag_trapping_math || flag_errno_math))
554 : 8884 : return false;
555 : : /* Similarly for nextafter (0, 1) raising underflow. */
556 : 6741 : else if (flag_trapping_math
557 : 6234 : && arg0->cl == rvc_zero
558 : 5490 : && result->cl != rvc_zero)
559 : : return false;
560 : :
561 : 1431 : real_convert (result, format, result);
562 : :
563 : 1431 : return true;
564 : : }
565 : :
566 : : /* Try to evaluate:
567 : :
568 : : *RESULT = ldexp (*ARG0, ARG1)
569 : :
570 : : in format FORMAT. Return true on success. */
571 : :
572 : : static bool
573 : 25261 : fold_const_builtin_load_exponent (real_value *result, const real_value *arg0,
574 : : const wide_int_ref &arg1,
575 : : const real_format *format)
576 : : {
577 : : /* Bound the maximum adjustment to twice the range of the
578 : : mode's valid exponents. Use abs to ensure the range is
579 : : positive as a sanity check. */
580 : 25261 : int max_exp_adj = 2 * labs (format->emax - format->emin);
581 : :
582 : : /* The requested adjustment must be inside this range. This
583 : : is a preliminary cap to avoid things like overflow, we
584 : : may still fail to compute the result for other reasons. */
585 : 42736 : if (wi::les_p (arg1, -max_exp_adj) || wi::ges_p (arg1, max_exp_adj))
586 : 15440 : return false;
587 : :
588 : : /* Don't perform operation if we honor signaling NaNs and
589 : : operand is a signaling NaN. */
590 : 9821 : if (!flag_unsafe_math_optimizations
591 : 9818 : && flag_signaling_nans
592 : 9941 : && REAL_VALUE_ISSIGNALING_NAN (*arg0))
593 : : return false;
594 : :
595 : 9821 : REAL_VALUE_TYPE initial_result;
596 : 9821 : real_ldexp (&initial_result, arg0, arg1.to_shwi ());
597 : :
598 : : /* Ensure we didn't overflow. */
599 : 9821 : if (real_isinf (&initial_result))
600 : : return false;
601 : :
602 : : /* Only proceed if the target mode can hold the
603 : : resulting value. */
604 : 9801 : *result = real_value_truncate (format, initial_result);
605 : 9801 : return real_equal (&initial_result, result);
606 : : }
607 : :
608 : : /* Fold a call to __builtin_nan or __builtin_nans with argument ARG and
609 : : return type TYPE. QUIET is true if a quiet rather than signalling
610 : : NaN is required. */
611 : :
612 : : static tree
613 : 341823 : fold_const_builtin_nan (tree type, tree arg, bool quiet)
614 : : {
615 : 341823 : REAL_VALUE_TYPE real;
616 : 341823 : const char *str = c_getstr (arg);
617 : 341823 : if (str && real_nan (&real, str, quiet, TYPE_MODE (type)))
618 : 341354 : return build_real (type, real);
619 : : return NULL_TREE;
620 : : }
621 : :
622 : : /* Fold a call to IFN_REDUC_<CODE> (ARG), returning a value of type TYPE. */
623 : :
624 : : static tree
625 : 2026 : fold_const_reduction (tree type, tree arg, tree_code code)
626 : : {
627 : 2026 : unsigned HOST_WIDE_INT nelts;
628 : 2026 : if (TREE_CODE (arg) != VECTOR_CST
629 : 2026 : || !VECTOR_CST_NELTS (arg).is_constant (&nelts))
630 : 0 : return NULL_TREE;
631 : :
632 : 2026 : tree res = VECTOR_CST_ELT (arg, 0);
633 : 25576 : for (unsigned HOST_WIDE_INT i = 1; i < nelts; i++)
634 : : {
635 : 23550 : res = const_binop (code, type, res, VECTOR_CST_ELT (arg, i));
636 : 23550 : if (res == NULL_TREE || !CONSTANT_CLASS_P (res))
637 : : return NULL_TREE;
638 : : }
639 : : return res;
640 : : }
641 : :
642 : : /* Fold a call to IFN_VEC_CONVERT (ARG) returning TYPE. */
643 : :
644 : : static tree
645 : 138 : fold_const_vec_convert (tree ret_type, tree arg)
646 : : {
647 : 138 : enum tree_code code = NOP_EXPR;
648 : 138 : tree arg_type = TREE_TYPE (arg);
649 : 138 : if (TREE_CODE (arg) != VECTOR_CST)
650 : : return NULL_TREE;
651 : :
652 : 138 : gcc_checking_assert (VECTOR_TYPE_P (ret_type) && VECTOR_TYPE_P (arg_type));
653 : :
654 : 276 : if (INTEGRAL_TYPE_P (TREE_TYPE (ret_type))
655 : 211 : && SCALAR_FLOAT_TYPE_P (TREE_TYPE (arg_type)))
656 : : code = FIX_TRUNC_EXPR;
657 : 170 : else if (INTEGRAL_TYPE_P (TREE_TYPE (arg_type))
658 : 170 : && SCALAR_FLOAT_TYPE_P (TREE_TYPE (ret_type)))
659 : : code = FLOAT_EXPR;
660 : :
661 : : /* We can't handle steps directly when extending, since the
662 : : values need to wrap at the original precision first. */
663 : 138 : bool step_ok_p
664 : 276 : = (INTEGRAL_TYPE_P (TREE_TYPE (ret_type))
665 : 73 : && INTEGRAL_TYPE_P (TREE_TYPE (arg_type))
666 : 158 : && (TYPE_PRECISION (TREE_TYPE (ret_type))
667 : 20 : <= TYPE_PRECISION (TREE_TYPE (arg_type))));
668 : 138 : tree_vector_builder elts;
669 : 138 : if (!elts.new_unary_operation (ret_type, arg, step_ok_p))
670 : : return NULL_TREE;
671 : :
672 : 138 : unsigned int count = elts.encoded_nelts ();
673 : 654 : for (unsigned int i = 0; i < count; ++i)
674 : : {
675 : 522 : tree elt = fold_unary (code, TREE_TYPE (ret_type),
676 : : VECTOR_CST_ELT (arg, i));
677 : 522 : if (elt == NULL_TREE || !CONSTANT_CLASS_P (elt))
678 : 6 : return NULL_TREE;
679 : 516 : elts.quick_push (elt);
680 : : }
681 : :
682 : 132 : return elts.build ();
683 : 138 : }
684 : :
685 : : /* Try to evaluate:
686 : :
687 : : IFN_WHILE_ULT (ARG0, ARG1, (TYPE) { ... })
688 : :
689 : : Return the value on success and null on failure. */
690 : :
691 : : static tree
692 : 0 : fold_while_ult (tree type, poly_uint64 arg0, poly_uint64 arg1)
693 : : {
694 : 0 : if (known_ge (arg0, arg1))
695 : 0 : return build_zero_cst (type);
696 : :
697 : 0 : if (maybe_ge (arg0, arg1))
698 : : return NULL_TREE;
699 : :
700 : 0 : poly_uint64 diff = arg1 - arg0;
701 : 0 : poly_uint64 nelts = TYPE_VECTOR_SUBPARTS (type);
702 : 0 : if (known_ge (diff, nelts))
703 : 0 : return build_all_ones_cst (type);
704 : :
705 : 0 : unsigned HOST_WIDE_INT const_diff;
706 : 0 : if (known_le (diff, nelts) && diff.is_constant (&const_diff))
707 : : {
708 : 0 : tree minus_one = build_minus_one_cst (TREE_TYPE (type));
709 : 0 : tree zero = build_zero_cst (TREE_TYPE (type));
710 : 0 : return build_vector_a_then_b (type, const_diff, minus_one, zero);
711 : : }
712 : : return NULL_TREE;
713 : : }
714 : :
715 : : /* Try to evaluate:
716 : :
717 : : *RESULT = FN (*ARG)
718 : :
719 : : in format FORMAT. Return true on success. */
720 : :
721 : : static bool
722 : 175184 : fold_const_call_ss (real_value *result, combined_fn fn,
723 : : const real_value *arg, const real_format *format)
724 : : {
725 : 175184 : switch (fn)
726 : : {
727 : 23771 : CASE_CFN_SQRT:
728 : 23771 : CASE_CFN_SQRT_FN:
729 : 23771 : return (real_compare (GE_EXPR, arg, &dconst0)
730 : 23771 : && do_mpfr_arg1 (result, mpfr_sqrt, arg, format));
731 : :
732 : 512 : CASE_CFN_CBRT:
733 : 512 : CASE_CFN_CBRT_FN:
734 : 512 : return do_mpfr_arg1 (result, mpfr_cbrt, arg, format);
735 : :
736 : 1976 : CASE_CFN_ASIN:
737 : 1976 : CASE_CFN_ASIN_FN:
738 : 1976 : return (real_compare (GE_EXPR, arg, &dconstm1)
739 : 1202 : && real_compare (LE_EXPR, arg, &dconst1)
740 : 2396 : && do_mpfr_arg1 (result, mpfr_asin, arg, format));
741 : :
742 : 2027 : CASE_CFN_ACOS:
743 : 2027 : CASE_CFN_ACOS_FN:
744 : 2027 : return (real_compare (GE_EXPR, arg, &dconstm1)
745 : 1253 : && real_compare (LE_EXPR, arg, &dconst1)
746 : 2506 : && do_mpfr_arg1 (result, mpfr_acos, arg, format));
747 : :
748 : 556 : CASE_CFN_ATAN:
749 : 556 : CASE_CFN_ATAN_FN:
750 : 556 : return do_mpfr_arg1 (result, mpfr_atan, arg, format);
751 : :
752 : 312 : CASE_CFN_ASINH:
753 : 312 : CASE_CFN_ASINH_FN:
754 : 312 : return do_mpfr_arg1 (result, mpfr_asinh, arg, format);
755 : :
756 : 1451 : CASE_CFN_ACOSH:
757 : 1451 : CASE_CFN_ACOSH_FN:
758 : 1451 : return (real_compare (GE_EXPR, arg, &dconst1)
759 : 1451 : && do_mpfr_arg1 (result, mpfr_acosh, arg, format));
760 : :
761 : 1906 : CASE_CFN_ATANH:
762 : 1906 : CASE_CFN_ATANH_FN:
763 : 1906 : return (real_compare (GE_EXPR, arg, &dconstm1)
764 : 1906 : && real_compare (LE_EXPR, arg, &dconst1)
765 : 3812 : && do_mpfr_arg1 (result, mpfr_atanh, arg, format));
766 : :
767 : 1018 : CASE_CFN_SIN:
768 : 1018 : CASE_CFN_SIN_FN:
769 : 1018 : return do_mpfr_arg1 (result, mpfr_sin, arg, format);
770 : :
771 : 850 : CASE_CFN_COS:
772 : 850 : CASE_CFN_COS_FN:
773 : 850 : return do_mpfr_arg1 (result, mpfr_cos, arg, format);
774 : :
775 : 557 : CASE_CFN_TAN:
776 : 557 : CASE_CFN_TAN_FN:
777 : 557 : return do_mpfr_arg1 (result, mpfr_tan, arg, format);
778 : :
779 : 394 : CASE_CFN_SINH:
780 : 394 : CASE_CFN_SINH_FN:
781 : 394 : return do_mpfr_arg1 (result, mpfr_sinh, arg, format);
782 : :
783 : 399 : CASE_CFN_COSH:
784 : 399 : CASE_CFN_COSH_FN:
785 : 399 : return do_mpfr_arg1 (result, mpfr_cosh, arg, format);
786 : :
787 : 349 : CASE_CFN_TANH:
788 : 349 : CASE_CFN_TANH_FN:
789 : 349 : return do_mpfr_arg1 (result, mpfr_tanh, arg, format);
790 : :
791 : : #if MPFR_VERSION >= MPFR_VERSION_NUM(4, 2, 0)
792 : 55 : CASE_CFN_ACOSPI:
793 : 55 : CASE_CFN_ACOSPI_FN:
794 : 55 : return (real_compare (GE_EXPR, arg, &dconstm1)
795 : 55 : && real_compare (LE_EXPR, arg, &dconst1)
796 : 110 : && do_mpfr_arg1 (result, mpfr_acospi, arg, format));
797 : :
798 : 60 : CASE_CFN_ASINPI:
799 : 60 : CASE_CFN_ASINPI_FN:
800 : 60 : return (real_compare (GE_EXPR, arg, &dconstm1)
801 : 60 : && real_compare (LE_EXPR, arg, &dconst1)
802 : 120 : && do_mpfr_arg1 (result, mpfr_asinpi, arg, format));
803 : :
804 : 36 : CASE_CFN_ATANPI:
805 : 36 : CASE_CFN_ATANPI_FN:
806 : 36 : return do_mpfr_arg1 (result, mpfr_atanpi, arg, format);
807 : :
808 : 60 : CASE_CFN_COSPI:
809 : 60 : CASE_CFN_COSPI_FN:
810 : 60 : return do_mpfr_arg1 (result, mpfr_cospi, arg, format);
811 : :
812 : 60 : CASE_CFN_SINPI:
813 : 60 : CASE_CFN_SINPI_FN:
814 : 60 : return do_mpfr_arg1 (result, mpfr_sinpi, arg, format);
815 : :
816 : 72 : CASE_CFN_TANPI:
817 : 72 : CASE_CFN_TANPI_FN:
818 : 72 : return do_mpfr_arg1 (result, mpfr_tanpi, arg, format);
819 : : #endif
820 : :
821 : 511 : CASE_CFN_ERF:
822 : 511 : CASE_CFN_ERF_FN:
823 : 511 : return do_mpfr_arg1 (result, mpfr_erf, arg, format);
824 : :
825 : 554 : CASE_CFN_ERFC:
826 : 554 : CASE_CFN_ERFC_FN:
827 : 554 : return do_mpfr_arg1 (result, mpfr_erfc, arg, format);
828 : :
829 : 4899 : CASE_CFN_TGAMMA:
830 : 4899 : CASE_CFN_TGAMMA_FN:
831 : 4899 : return do_mpfr_arg1 (result, mpfr_gamma, arg, format);
832 : :
833 : 872 : CASE_CFN_EXP:
834 : 872 : CASE_CFN_EXP_FN:
835 : 872 : return do_mpfr_arg1 (result, mpfr_exp, arg, format);
836 : :
837 : 10784 : CASE_CFN_EXP2:
838 : 10784 : CASE_CFN_EXP2_FN:
839 : 10784 : return do_mpfr_arg1 (result, mpfr_exp2, arg, format);
840 : :
841 : 698 : CASE_CFN_EXP10:
842 : 698 : CASE_CFN_POW10:
843 : 698 : return do_mpfr_arg1 (result, mpfr_exp10, arg, format);
844 : :
845 : 327 : CASE_CFN_EXPM1:
846 : 327 : CASE_CFN_EXPM1_FN:
847 : 327 : return do_mpfr_arg1 (result, mpfr_expm1, arg, format);
848 : :
849 : 73515 : CASE_CFN_LOG:
850 : 73515 : CASE_CFN_LOG_FN:
851 : 73515 : return (real_compare (GT_EXPR, arg, &dconst0)
852 : 73515 : && do_mpfr_arg1 (result, mpfr_log, arg, format));
853 : :
854 : 3136 : CASE_CFN_LOG2:
855 : 3136 : CASE_CFN_LOG2_FN:
856 : 3136 : return (real_compare (GT_EXPR, arg, &dconst0)
857 : 3136 : && do_mpfr_arg1 (result, mpfr_log2, arg, format));
858 : :
859 : 3171 : CASE_CFN_LOG10:
860 : 3171 : CASE_CFN_LOG10_FN:
861 : 3171 : return (real_compare (GT_EXPR, arg, &dconst0)
862 : 3171 : && do_mpfr_arg1 (result, mpfr_log10, arg, format));
863 : :
864 : 1921 : CASE_CFN_LOG1P:
865 : 1921 : CASE_CFN_LOG1P_FN:
866 : 1921 : return (real_compare (GT_EXPR, arg, &dconstm1)
867 : 1921 : && do_mpfr_arg1 (result, mpfr_log1p, arg, format));
868 : :
869 : 221 : CASE_CFN_J0:
870 : 221 : return do_mpfr_arg1 (result, mpfr_j0, arg, format);
871 : :
872 : 221 : CASE_CFN_J1:
873 : 221 : return do_mpfr_arg1 (result, mpfr_j1, arg, format);
874 : :
875 : 2447 : CASE_CFN_Y0:
876 : 2447 : return (real_compare (GT_EXPR, arg, &dconst0)
877 : 2447 : && do_mpfr_arg1 (result, mpfr_y0, arg, format));
878 : :
879 : 2447 : CASE_CFN_Y1:
880 : 2447 : return (real_compare (GT_EXPR, arg, &dconst0)
881 : 2447 : && do_mpfr_arg1 (result, mpfr_y1, arg, format));
882 : :
883 : 362 : CASE_CFN_FLOOR:
884 : 362 : CASE_CFN_FLOOR_FN:
885 : 362 : if (!REAL_VALUE_ISSIGNALING_NAN (*arg))
886 : : {
887 : 362 : real_floor (result, format, arg);
888 : 362 : return true;
889 : : }
890 : : return false;
891 : :
892 : 321 : CASE_CFN_CEIL:
893 : 321 : CASE_CFN_CEIL_FN:
894 : 321 : if (!REAL_VALUE_ISSIGNALING_NAN (*arg))
895 : : {
896 : 321 : real_ceil (result, format, arg);
897 : 321 : return true;
898 : : }
899 : : return false;
900 : :
901 : 532 : CASE_CFN_TRUNC:
902 : 532 : CASE_CFN_TRUNC_FN:
903 : 532 : if (!REAL_VALUE_ISSIGNALING_NAN (*arg))
904 : : {
905 : 532 : real_trunc (result, format, arg);
906 : 532 : return true;
907 : : }
908 : : return false;
909 : :
910 : 273 : CASE_CFN_ROUND:
911 : 273 : CASE_CFN_ROUND_FN:
912 : 273 : if (!REAL_VALUE_ISSIGNALING_NAN (*arg))
913 : : {
914 : 273 : real_round (result, format, arg);
915 : 273 : return true;
916 : : }
917 : : return false;
918 : :
919 : 189 : CASE_CFN_ROUNDEVEN:
920 : 189 : CASE_CFN_ROUNDEVEN_FN:
921 : 189 : if (!REAL_VALUE_ISSIGNALING_NAN (*arg))
922 : : {
923 : 189 : real_roundeven (result, format, arg);
924 : 189 : return true;
925 : : }
926 : : return false;
927 : :
928 : 4463 : CASE_CFN_LOGB:
929 : 4463 : CASE_CFN_LOGB_FN:
930 : 4463 : return fold_const_logb (result, arg, format);
931 : :
932 : 960 : CASE_CFN_SIGNIFICAND:
933 : 960 : return fold_const_significand (result, arg, format);
934 : :
935 : : default:
936 : : return false;
937 : : }
938 : : }
939 : :
940 : : /* Try to evaluate:
941 : :
942 : : *RESULT = FN (*ARG)
943 : :
944 : : where FORMAT is the format of ARG and PRECISION is the number of
945 : : significant bits in the result. Return true on success. */
946 : :
947 : : static bool
948 : 17640 : fold_const_call_ss (wide_int *result, combined_fn fn,
949 : : const real_value *arg, unsigned int precision,
950 : : const real_format *format)
951 : : {
952 : 17640 : switch (fn)
953 : : {
954 : 1885 : CASE_CFN_SIGNBIT:
955 : 1885 : if (real_isneg (arg))
956 : 1011 : *result = wi::one (precision);
957 : : else
958 : 874 : *result = wi::zero (precision);
959 : : return true;
960 : :
961 : 6465 : CASE_CFN_ILOGB:
962 : 6465 : CASE_CFN_ILOGB_FN:
963 : : /* For ilogb we don't know FP_ILOGB0, so only handle normal values.
964 : : Proceed iff radix == 2. In GCC, normalized significands are in
965 : : the range [0.5, 1.0). We want the exponent as if they were
966 : : [1.0, 2.0) so get the exponent and subtract 1. */
967 : 6465 : if (arg->cl == rvc_normal && format->b == 2)
968 : : {
969 : 834 : *result = wi::shwi (REAL_EXP (arg) - 1, precision);
970 : 834 : return true;
971 : : }
972 : : return false;
973 : :
974 : 378 : CASE_CFN_ICEIL:
975 : 378 : CASE_CFN_LCEIL:
976 : 378 : CASE_CFN_LLCEIL:
977 : 378 : return fold_const_conversion (result, real_ceil, arg,
978 : 378 : precision, format);
979 : :
980 : 378 : CASE_CFN_LFLOOR:
981 : 378 : CASE_CFN_IFLOOR:
982 : 378 : CASE_CFN_LLFLOOR:
983 : 378 : return fold_const_conversion (result, real_floor, arg,
984 : 378 : precision, format);
985 : :
986 : 884 : CASE_CFN_IROUND:
987 : 884 : CASE_CFN_LROUND:
988 : 884 : CASE_CFN_LROUND_FN:
989 : 884 : CASE_CFN_LLROUND:
990 : 884 : CASE_CFN_LLROUND_FN:
991 : 884 : return fold_const_conversion (result, real_round, arg,
992 : 884 : precision, format);
993 : :
994 : : CASE_CFN_IRINT:
995 : : CASE_CFN_LRINT:
996 : : CASE_CFN_LRINT_FN:
997 : : CASE_CFN_LLRINT:
998 : : CASE_CFN_LLRINT_FN:
999 : : /* Not yet folded to a constant. */
1000 : : return false;
1001 : :
1002 : 1503 : CASE_CFN_FINITE:
1003 : 1503 : case CFN_BUILT_IN_FINITED32:
1004 : 1503 : case CFN_BUILT_IN_FINITED64:
1005 : 1503 : case CFN_BUILT_IN_FINITED128:
1006 : 1503 : case CFN_BUILT_IN_ISFINITE:
1007 : 1537 : *result = wi::shwi (real_isfinite (arg) ? 1 : 0, precision);
1008 : 1503 : return true;
1009 : :
1010 : 3808 : case CFN_BUILT_IN_ISSIGNALING:
1011 : 7445 : *result = wi::shwi (real_issignaling_nan (arg) ? 1 : 0, precision);
1012 : 3808 : return true;
1013 : :
1014 : 204 : CASE_CFN_ISINF:
1015 : 204 : case CFN_BUILT_IN_ISINFD32:
1016 : 204 : case CFN_BUILT_IN_ISINFD64:
1017 : 204 : case CFN_BUILT_IN_ISINFD128:
1018 : 204 : if (real_isinf (arg))
1019 : 295 : *result = wi::shwi (arg->sign ? -1 : 1, precision);
1020 : : else
1021 : 40 : *result = wi::shwi (0, precision);
1022 : : return true;
1023 : :
1024 : 1347 : CASE_CFN_ISNAN:
1025 : 1347 : case CFN_BUILT_IN_ISNAND32:
1026 : 1347 : case CFN_BUILT_IN_ISNAND64:
1027 : 1347 : case CFN_BUILT_IN_ISNAND128:
1028 : 2462 : *result = wi::shwi (real_isnan (arg) ? 1 : 0, precision);
1029 : 1347 : return true;
1030 : :
1031 : : default:
1032 : : return false;
1033 : : }
1034 : : }
1035 : :
1036 : : /* Try to evaluate:
1037 : :
1038 : : *RESULT = FN (ARG)
1039 : :
1040 : : where ARG_TYPE is the type of ARG and PRECISION is the number of bits
1041 : : in the result. Return true on success. */
1042 : :
1043 : : static bool
1044 : 3346105 : fold_const_call_ss (wide_int *result, combined_fn fn, const wide_int_ref &arg,
1045 : : unsigned int precision, tree arg_type)
1046 : : {
1047 : 3346105 : switch (fn)
1048 : : {
1049 : 493 : CASE_CFN_FFS:
1050 : 493 : case CFN_BUILT_IN_FFSG:
1051 : 493 : *result = wi::shwi (wi::ffs (arg), precision);
1052 : 493 : return true;
1053 : :
1054 : 2418 : CASE_CFN_CLZ:
1055 : 2418 : case CFN_BUILT_IN_CLZG:
1056 : 2418 : {
1057 : 2418 : int tmp;
1058 : 2418 : if (wi::ne_p (arg, 0))
1059 : 2080 : tmp = wi::clz (arg);
1060 : 338 : else if (TREE_CODE (arg_type) == BITINT_TYPE)
1061 : 9 : tmp = TYPE_PRECISION (arg_type);
1062 : 658 : else if (!CLZ_DEFINED_VALUE_AT_ZERO (SCALAR_INT_TYPE_MODE (arg_type),
1063 : : tmp))
1064 : 329 : tmp = TYPE_PRECISION (arg_type);
1065 : 2418 : *result = wi::shwi (tmp, precision);
1066 : 2418 : return true;
1067 : : }
1068 : :
1069 : 804 : CASE_CFN_CTZ:
1070 : 804 : case CFN_BUILT_IN_CTZG:
1071 : 804 : {
1072 : 804 : int tmp;
1073 : 804 : if (wi::ne_p (arg, 0))
1074 : 560 : tmp = wi::ctz (arg);
1075 : 244 : else if (TREE_CODE (arg_type) == BITINT_TYPE)
1076 : 0 : tmp = TYPE_PRECISION (arg_type);
1077 : 488 : else if (!CTZ_DEFINED_VALUE_AT_ZERO (SCALAR_INT_TYPE_MODE (arg_type),
1078 : : tmp))
1079 : 244 : tmp = TYPE_PRECISION (arg_type);
1080 : 804 : *result = wi::shwi (tmp, precision);
1081 : 804 : return true;
1082 : : }
1083 : :
1084 : 412 : CASE_CFN_CLRSB:
1085 : 412 : case CFN_BUILT_IN_CLRSBG:
1086 : 412 : *result = wi::shwi (wi::clrsb (arg), precision);
1087 : 412 : return true;
1088 : :
1089 : 2067 : CASE_CFN_POPCOUNT:
1090 : 2067 : case CFN_BUILT_IN_POPCOUNTG:
1091 : 2067 : *result = wi::shwi (wi::popcount (arg), precision);
1092 : 2067 : return true;
1093 : :
1094 : 545 : CASE_CFN_PARITY:
1095 : 545 : case CFN_BUILT_IN_PARITYG:
1096 : 545 : *result = wi::shwi (wi::parity (arg), precision);
1097 : 545 : return true;
1098 : :
1099 : 719 : case CFN_BUILT_IN_BSWAP16:
1100 : 719 : case CFN_BUILT_IN_BSWAP32:
1101 : 719 : case CFN_BUILT_IN_BSWAP64:
1102 : 719 : case CFN_BUILT_IN_BSWAP128:
1103 : 1438 : *result = wi::bswap (wide_int::from (arg, precision,
1104 : 1438 : TYPE_SIGN (arg_type)));
1105 : 719 : return true;
1106 : :
1107 : : default:
1108 : : return false;
1109 : : }
1110 : : }
1111 : :
1112 : : /* Try to evaluate:
1113 : :
1114 : : RESULT = FN (*ARG)
1115 : :
1116 : : where FORMAT is the format of ARG and of the real and imaginary parts
1117 : : of RESULT, passed as RESULT_REAL and RESULT_IMAG respectively. Return
1118 : : true on success. */
1119 : :
1120 : : static bool
1121 : 154 : fold_const_call_cs (real_value *result_real, real_value *result_imag,
1122 : : combined_fn fn, const real_value *arg,
1123 : : const real_format *format)
1124 : : {
1125 : 0 : switch (fn)
1126 : : {
1127 : 154 : CASE_CFN_CEXPI:
1128 : : /* cexpi(x+yi) = cos(x)+sin(y)*i. */
1129 : 154 : return do_mpfr_sincos (result_imag, result_real, arg, format);
1130 : :
1131 : : default:
1132 : : return false;
1133 : : }
1134 : : }
1135 : :
1136 : : /* Try to evaluate:
1137 : :
1138 : : *RESULT = fn (ARG)
1139 : :
1140 : : where FORMAT is the format of RESULT and of the real and imaginary parts
1141 : : of ARG, passed as ARG_REAL and ARG_IMAG respectively. Return true on
1142 : : success. */
1143 : :
1144 : : static bool
1145 : 2282 : fold_const_call_sc (real_value *result, combined_fn fn,
1146 : : const real_value *arg_real, const real_value *arg_imag,
1147 : : const real_format *format)
1148 : : {
1149 : 0 : switch (fn)
1150 : : {
1151 : 1146 : CASE_CFN_CABS:
1152 : 1146 : CASE_CFN_CABS_FN:
1153 : 1146 : return do_mpfr_arg2 (result, mpfr_hypot, arg_real, arg_imag, format);
1154 : :
1155 : : default:
1156 : : return false;
1157 : : }
1158 : : }
1159 : :
1160 : : /* Try to evaluate:
1161 : :
1162 : : RESULT = fn (ARG)
1163 : :
1164 : : where FORMAT is the format of the real and imaginary parts of RESULT
1165 : : (RESULT_REAL and RESULT_IMAG) and of ARG (ARG_REAL and ARG_IMAG).
1166 : : Return true on success. */
1167 : :
1168 : : static bool
1169 : 38647 : fold_const_call_cc (real_value *result_real, real_value *result_imag,
1170 : : combined_fn fn, const real_value *arg_real,
1171 : : const real_value *arg_imag, const real_format *format)
1172 : : {
1173 : 38647 : switch (fn)
1174 : : {
1175 : 686 : CASE_CFN_CCOS:
1176 : 686 : CASE_CFN_CCOS_FN:
1177 : 686 : return do_mpc_arg1 (result_real, result_imag, mpc_cos,
1178 : 686 : arg_real, arg_imag, format);
1179 : :
1180 : 676 : CASE_CFN_CCOSH:
1181 : 676 : CASE_CFN_CCOSH_FN:
1182 : 676 : return do_mpc_arg1 (result_real, result_imag, mpc_cosh,
1183 : 676 : arg_real, arg_imag, format);
1184 : :
1185 : 683 : CASE_CFN_CPROJ:
1186 : 683 : CASE_CFN_CPROJ_FN:
1187 : 683 : if (real_isinf (arg_real) || real_isinf (arg_imag))
1188 : : {
1189 : 436 : *result_real = dconstinf;
1190 : 436 : *result_imag = dconst0;
1191 : 436 : result_imag->sign = arg_imag->sign;
1192 : : }
1193 : : else
1194 : : {
1195 : 247 : *result_real = *arg_real;
1196 : 247 : *result_imag = *arg_imag;
1197 : : }
1198 : : return true;
1199 : :
1200 : 686 : CASE_CFN_CSIN:
1201 : 686 : CASE_CFN_CSIN_FN:
1202 : 686 : return do_mpc_arg1 (result_real, result_imag, mpc_sin,
1203 : 686 : arg_real, arg_imag, format);
1204 : :
1205 : 676 : CASE_CFN_CSINH:
1206 : 676 : CASE_CFN_CSINH_FN:
1207 : 676 : return do_mpc_arg1 (result_real, result_imag, mpc_sinh,
1208 : 676 : arg_real, arg_imag, format);
1209 : :
1210 : 698 : CASE_CFN_CTAN:
1211 : 698 : CASE_CFN_CTAN_FN:
1212 : 698 : return do_mpc_arg1 (result_real, result_imag, mpc_tan,
1213 : 698 : arg_real, arg_imag, format);
1214 : :
1215 : 676 : CASE_CFN_CTANH:
1216 : 676 : CASE_CFN_CTANH_FN:
1217 : 676 : return do_mpc_arg1 (result_real, result_imag, mpc_tanh,
1218 : 676 : arg_real, arg_imag, format);
1219 : :
1220 : 777 : CASE_CFN_CLOG:
1221 : 777 : CASE_CFN_CLOG_FN:
1222 : 777 : return do_mpc_arg1 (result_real, result_imag, mpc_log,
1223 : 777 : arg_real, arg_imag, format);
1224 : :
1225 : 3053 : CASE_CFN_CSQRT:
1226 : 3053 : CASE_CFN_CSQRT_FN:
1227 : 3053 : return do_mpc_arg1 (result_real, result_imag, mpc_sqrt,
1228 : 3053 : arg_real, arg_imag, format);
1229 : :
1230 : 679 : CASE_CFN_CASIN:
1231 : 679 : CASE_CFN_CASIN_FN:
1232 : 679 : return do_mpc_arg1 (result_real, result_imag, mpc_asin,
1233 : 679 : arg_real, arg_imag, format);
1234 : :
1235 : 728 : CASE_CFN_CACOS:
1236 : 728 : CASE_CFN_CACOS_FN:
1237 : 728 : return do_mpc_arg1 (result_real, result_imag, mpc_acos,
1238 : 728 : arg_real, arg_imag, format);
1239 : :
1240 : 679 : CASE_CFN_CATAN:
1241 : 679 : CASE_CFN_CATAN_FN:
1242 : 679 : return do_mpc_arg1 (result_real, result_imag, mpc_atan,
1243 : 679 : arg_real, arg_imag, format);
1244 : :
1245 : 679 : CASE_CFN_CASINH:
1246 : 679 : CASE_CFN_CASINH_FN:
1247 : 679 : return do_mpc_arg1 (result_real, result_imag, mpc_asinh,
1248 : 679 : arg_real, arg_imag, format);
1249 : :
1250 : 745 : CASE_CFN_CACOSH:
1251 : 745 : CASE_CFN_CACOSH_FN:
1252 : 745 : return do_mpc_arg1 (result_real, result_imag, mpc_acosh,
1253 : 745 : arg_real, arg_imag, format);
1254 : :
1255 : 679 : CASE_CFN_CATANH:
1256 : 679 : CASE_CFN_CATANH_FN:
1257 : 679 : return do_mpc_arg1 (result_real, result_imag, mpc_atanh,
1258 : 679 : arg_real, arg_imag, format);
1259 : :
1260 : 1583 : CASE_CFN_CEXP:
1261 : 1583 : CASE_CFN_CEXP_FN:
1262 : 1583 : return do_mpc_arg1 (result_real, result_imag, mpc_exp,
1263 : 1583 : arg_real, arg_imag, format);
1264 : :
1265 : : default:
1266 : : return false;
1267 : : }
1268 : : }
1269 : :
1270 : : /* Subroutine of fold_const_call, with the same interface. Handle cases
1271 : : where the arguments and result are numerical. */
1272 : :
1273 : : static tree
1274 : 16285591 : fold_const_call_1 (combined_fn fn, tree type, tree arg)
1275 : : {
1276 : 16285591 : machine_mode mode = TYPE_MODE (type);
1277 : 16285591 : machine_mode arg_mode = TYPE_MODE (TREE_TYPE (arg));
1278 : :
1279 : 16285591 : if (integer_cst_p (arg))
1280 : : {
1281 : 3566243 : if (SCALAR_INT_MODE_P (mode))
1282 : : {
1283 : 3346105 : wide_int result;
1284 : 3346105 : if (fold_const_call_ss (&result, fn, wi::to_wide (arg),
1285 : 3346105 : TYPE_PRECISION (type), TREE_TYPE (arg)))
1286 : 7458 : return wide_int_to_tree (type, result);
1287 : 3346105 : }
1288 : 3558785 : return NULL_TREE;
1289 : : }
1290 : :
1291 : 12719348 : if (real_cst_p (arg))
1292 : : {
1293 : 192981 : gcc_checking_assert (SCALAR_FLOAT_MODE_P (arg_mode));
1294 : 192981 : if (mode == arg_mode)
1295 : : {
1296 : : /* real -> real. */
1297 : 175184 : REAL_VALUE_TYPE result;
1298 : 175184 : if (fold_const_call_ss (&result, fn, TREE_REAL_CST_PTR (arg),
1299 : 175184 : REAL_MODE_FORMAT (mode)))
1300 : 113907 : return build_real (type, result);
1301 : : }
1302 : 17797 : else if (COMPLEX_MODE_P (mode)
1303 : 17951 : && GET_MODE_INNER (mode) == arg_mode)
1304 : : {
1305 : : /* real -> complex real. */
1306 : 154 : REAL_VALUE_TYPE result_real, result_imag;
1307 : 308 : if (fold_const_call_cs (&result_real, &result_imag, fn,
1308 : 154 : TREE_REAL_CST_PTR (arg),
1309 : 154 : REAL_MODE_FORMAT (arg_mode)))
1310 : 308 : return build_complex (type,
1311 : 154 : build_real (TREE_TYPE (type), result_real),
1312 : 308 : build_real (TREE_TYPE (type), result_imag));
1313 : : }
1314 : 17643 : else if (INTEGRAL_TYPE_P (type))
1315 : : {
1316 : : /* real -> int. */
1317 : 17640 : wide_int result;
1318 : 17640 : if (fold_const_call_ss (&result, fn,
1319 : 17640 : TREE_REAL_CST_PTR (arg),
1320 : 17640 : TYPE_PRECISION (type),
1321 : 17640 : REAL_MODE_FORMAT (arg_mode)))
1322 : 11221 : return wide_int_to_tree (type, result);
1323 : 17640 : }
1324 : 67699 : return NULL_TREE;
1325 : : }
1326 : :
1327 : 12526367 : if (complex_cst_p (arg))
1328 : : {
1329 : 40929 : gcc_checking_assert (COMPLEX_MODE_P (arg_mode));
1330 : 40929 : machine_mode inner_mode = GET_MODE_INNER (arg_mode);
1331 : 40929 : tree argr = TREE_REALPART (arg);
1332 : 40929 : tree argi = TREE_IMAGPART (arg);
1333 : 40929 : if (mode == arg_mode
1334 : 38647 : && real_cst_p (argr)
1335 : 79576 : && real_cst_p (argi))
1336 : : {
1337 : : /* complex real -> complex real. */
1338 : 38647 : REAL_VALUE_TYPE result_real, result_imag;
1339 : 77294 : if (fold_const_call_cc (&result_real, &result_imag, fn,
1340 : 38647 : TREE_REAL_CST_PTR (argr),
1341 : 38647 : TREE_REAL_CST_PTR (argi),
1342 : 38647 : REAL_MODE_FORMAT (inner_mode)))
1343 : 20942 : return build_complex (type,
1344 : 10471 : build_real (TREE_TYPE (type), result_real),
1345 : 20942 : build_real (TREE_TYPE (type), result_imag));
1346 : : }
1347 : 30458 : if (mode == inner_mode
1348 : 2282 : && real_cst_p (argr)
1349 : 32740 : && real_cst_p (argi))
1350 : : {
1351 : : /* complex real -> real. */
1352 : 2282 : REAL_VALUE_TYPE result;
1353 : 4564 : if (fold_const_call_sc (&result, fn,
1354 : 2282 : TREE_REAL_CST_PTR (argr),
1355 : 2282 : TREE_REAL_CST_PTR (argi),
1356 : 2282 : REAL_MODE_FORMAT (inner_mode)))
1357 : 1146 : return build_real (type, result);
1358 : : }
1359 : 29312 : return NULL_TREE;
1360 : : }
1361 : :
1362 : : return NULL_TREE;
1363 : : }
1364 : :
1365 : : /* Try to fold FN (ARG) to a constant. Return the constant on success,
1366 : : otherwise return null. TYPE is the type of the return value. */
1367 : :
1368 : : tree
1369 : 17111133 : fold_const_call (combined_fn fn, tree type, tree arg)
1370 : : {
1371 : 17111133 : switch (fn)
1372 : : {
1373 : 481555 : case CFN_BUILT_IN_STRLEN:
1374 : 481555 : if (const char *str = c_getstr (arg))
1375 : 49604 : return build_int_cst (type, strlen (str));
1376 : : return NULL_TREE;
1377 : :
1378 : 199684 : CASE_CFN_NAN:
1379 : 199684 : CASE_FLT_FN_FLOATN_NX (CFN_BUILT_IN_NAN):
1380 : 199684 : case CFN_BUILT_IN_NAND32:
1381 : 199684 : case CFN_BUILT_IN_NAND64:
1382 : 199684 : case CFN_BUILT_IN_NAND128:
1383 : 199684 : case CFN_BUILT_IN_NAND64X:
1384 : 199684 : return fold_const_builtin_nan (type, arg, true);
1385 : :
1386 : 142139 : CASE_CFN_NANS:
1387 : 142139 : CASE_FLT_FN_FLOATN_NX (CFN_BUILT_IN_NANS):
1388 : 142139 : case CFN_BUILT_IN_NANSF16B:
1389 : 142139 : case CFN_BUILT_IN_NANSD32:
1390 : 142139 : case CFN_BUILT_IN_NANSD64:
1391 : 142139 : case CFN_BUILT_IN_NANSD128:
1392 : 142139 : case CFN_BUILT_IN_NANSD64X:
1393 : 142139 : return fold_const_builtin_nan (type, arg, false);
1394 : :
1395 : 1666 : case CFN_REDUC_PLUS:
1396 : 1666 : return fold_const_reduction (type, arg, PLUS_EXPR);
1397 : :
1398 : 47 : case CFN_REDUC_MAX:
1399 : 47 : return fold_const_reduction (type, arg, MAX_EXPR);
1400 : :
1401 : 67 : case CFN_REDUC_MIN:
1402 : 67 : return fold_const_reduction (type, arg, MIN_EXPR);
1403 : :
1404 : 34 : case CFN_REDUC_AND:
1405 : 34 : return fold_const_reduction (type, arg, BIT_AND_EXPR);
1406 : :
1407 : 206 : case CFN_REDUC_IOR:
1408 : 206 : return fold_const_reduction (type, arg, BIT_IOR_EXPR);
1409 : :
1410 : 6 : case CFN_REDUC_XOR:
1411 : 6 : return fold_const_reduction (type, arg, BIT_XOR_EXPR);
1412 : :
1413 : 138 : case CFN_VEC_CONVERT:
1414 : 138 : return fold_const_vec_convert (type, arg);
1415 : :
1416 : 16285591 : default:
1417 : 16285591 : return fold_const_call_1 (fn, type, arg);
1418 : : }
1419 : : }
1420 : :
1421 : : /* Fold a call to IFN_FOLD_LEFT_<CODE> (ARG0, ARG1), returning a value
1422 : : of type TYPE. */
1423 : :
1424 : : static tree
1425 : 0 : fold_const_fold_left (tree type, tree arg0, tree arg1, tree_code code)
1426 : : {
1427 : 0 : if (TREE_CODE (arg1) != VECTOR_CST)
1428 : : return NULL_TREE;
1429 : :
1430 : 0 : unsigned HOST_WIDE_INT nelts;
1431 : 0 : if (!VECTOR_CST_NELTS (arg1).is_constant (&nelts))
1432 : : return NULL_TREE;
1433 : :
1434 : 0 : for (unsigned HOST_WIDE_INT i = 0; i < nelts; i++)
1435 : : {
1436 : 0 : arg0 = const_binop (code, type, arg0, VECTOR_CST_ELT (arg1, i));
1437 : 0 : if (arg0 == NULL_TREE || !CONSTANT_CLASS_P (arg0))
1438 : : return NULL_TREE;
1439 : : }
1440 : : return arg0;
1441 : : }
1442 : :
1443 : : /* Fold a call to IFN_VEC_SHL_INSERT (ARG0, ARG1), returning a value
1444 : : of type TYPE. */
1445 : :
1446 : : static tree
1447 : 0 : fold_const_vec_shl_insert (tree, tree arg0, tree arg1)
1448 : : {
1449 : 0 : if (TREE_CODE (arg0) != VECTOR_CST)
1450 : : return NULL_TREE;
1451 : :
1452 : : /* vec_shl_insert ( dup(CST), CST) -> dup (CST). */
1453 : 0 : if (tree elem = uniform_vector_p (arg0))
1454 : : {
1455 : 0 : if (operand_equal_p (elem, arg1))
1456 : : return arg0;
1457 : : }
1458 : :
1459 : : return NULL_TREE;
1460 : : }
1461 : :
1462 : : /* Try to evaluate:
1463 : :
1464 : : *RESULT = FN (*ARG0, *ARG1)
1465 : :
1466 : : in format FORMAT. Return true on success. */
1467 : :
1468 : : static bool
1469 : 233619 : fold_const_call_sss (real_value *result, combined_fn fn,
1470 : : const real_value *arg0, const real_value *arg1,
1471 : : const real_format *format)
1472 : : {
1473 : 233619 : switch (fn)
1474 : : {
1475 : 6774 : CASE_CFN_DREM:
1476 : 6774 : CASE_CFN_REMAINDER:
1477 : 6774 : CASE_CFN_REMAINDER_FN:
1478 : 6774 : return do_mpfr_arg2 (result, mpfr_remainder, arg0, arg1, format);
1479 : :
1480 : 983 : CASE_CFN_ATAN2:
1481 : 983 : CASE_CFN_ATAN2_FN:
1482 : 983 : return do_mpfr_arg2 (result, mpfr_atan2, arg0, arg1, format);
1483 : :
1484 : : #if MPFR_VERSION >= MPFR_VERSION_NUM(4, 2, 0)
1485 : 84 : CASE_CFN_ATAN2PI:
1486 : 84 : CASE_CFN_ATAN2PI_FN:
1487 : 84 : return do_mpfr_arg2 (result, mpfr_atan2pi, arg0, arg1, format);
1488 : : #endif
1489 : :
1490 : 572 : CASE_CFN_FDIM:
1491 : 572 : CASE_CFN_FDIM_FN:
1492 : 572 : return do_mpfr_arg2 (result, mpfr_dim, arg0, arg1, format);
1493 : :
1494 : 517 : CASE_CFN_FMOD:
1495 : 517 : CASE_CFN_FMOD_FN:
1496 : 517 : return do_mpfr_arg2 (result, mpfr_fmod, arg0, arg1, format);
1497 : :
1498 : 578 : CASE_CFN_HYPOT:
1499 : 578 : CASE_CFN_HYPOT_FN:
1500 : 578 : return do_mpfr_arg2 (result, mpfr_hypot, arg0, arg1, format);
1501 : :
1502 : 70636 : CASE_CFN_COPYSIGN:
1503 : 70636 : CASE_CFN_COPYSIGN_FN:
1504 : 70636 : *result = *arg0;
1505 : 70636 : real_copysign (result, arg1);
1506 : 70636 : return true;
1507 : :
1508 : 3161 : CASE_CFN_FMIN:
1509 : 3161 : CASE_CFN_FMIN_FN:
1510 : 3161 : return do_mpfr_arg2 (result, mpfr_min, arg0, arg1, format);
1511 : :
1512 : 3161 : CASE_CFN_FMAX:
1513 : 3161 : CASE_CFN_FMAX_FN:
1514 : 3161 : return do_mpfr_arg2 (result, mpfr_max, arg0, arg1, format);
1515 : :
1516 : 131528 : CASE_CFN_POW:
1517 : 131528 : CASE_CFN_POW_FN:
1518 : 131528 : return fold_const_pow (result, arg0, arg1, format);
1519 : :
1520 : 15625 : CASE_CFN_NEXTAFTER:
1521 : 15625 : CASE_CFN_NEXTAFTER_FN:
1522 : 15625 : case CFN_BUILT_IN_NEXTAFTERF16B:
1523 : 15625 : CASE_CFN_NEXTTOWARD:
1524 : 15625 : return fold_const_nextafter (result, arg0, arg1, format);
1525 : :
1526 : : default:
1527 : : return false;
1528 : : }
1529 : : }
1530 : :
1531 : : /* Try to evaluate:
1532 : :
1533 : : *RESULT = FN (*ARG0, ARG1)
1534 : :
1535 : : where FORMAT is the format of *RESULT and *ARG0. Return true on
1536 : : success. */
1537 : :
1538 : : static bool
1539 : 25648 : fold_const_call_sss (real_value *result, combined_fn fn,
1540 : : const real_value *arg0, const wide_int_ref &arg1,
1541 : : const real_format *format)
1542 : : {
1543 : 25648 : switch (fn)
1544 : : {
1545 : 7912 : CASE_CFN_LDEXP:
1546 : 7912 : CASE_CFN_LDEXP_FN:
1547 : 7912 : return fold_const_builtin_load_exponent (result, arg0, arg1, format);
1548 : :
1549 : 17349 : CASE_CFN_SCALBN:
1550 : 17349 : CASE_CFN_SCALBN_FN:
1551 : 17349 : CASE_CFN_SCALBLN:
1552 : 17349 : CASE_CFN_SCALBLN_FN:
1553 : 17349 : return (format->b == 2
1554 : 17349 : && fold_const_builtin_load_exponent (result, arg0, arg1,
1555 : : format));
1556 : :
1557 : 378 : CASE_CFN_POWI:
1558 : : /* Avoid the folding if flag_signaling_nans is on and
1559 : : operand is a signaling NaN. */
1560 : 378 : if (!flag_unsafe_math_optimizations
1561 : 365 : && flag_signaling_nans
1562 : 393 : && REAL_VALUE_ISSIGNALING_NAN (*arg0))
1563 : : return false;
1564 : :
1565 : 378 : real_powi (result, format, arg0, arg1.to_shwi ());
1566 : 378 : return true;
1567 : :
1568 : : default:
1569 : : return false;
1570 : : }
1571 : : }
1572 : :
1573 : : /* Try to evaluate:
1574 : :
1575 : : *RESULT = FN (ARG0, *ARG1)
1576 : :
1577 : : where FORMAT is the format of *RESULT and *ARG1. Return true on
1578 : : success. */
1579 : :
1580 : : static bool
1581 : 6422 : fold_const_call_sss (real_value *result, combined_fn fn,
1582 : : const wide_int_ref &arg0, const real_value *arg1,
1583 : : const real_format *format)
1584 : : {
1585 : 6422 : switch (fn)
1586 : : {
1587 : 1208 : CASE_CFN_JN:
1588 : 1208 : return do_mpfr_arg2 (result, mpfr_jn, arg0, arg1, format);
1589 : :
1590 : 5205 : CASE_CFN_YN:
1591 : 5205 : return (real_compare (GT_EXPR, arg1, &dconst0)
1592 : 5205 : && do_mpfr_arg2 (result, mpfr_yn, arg0, arg1, format));
1593 : :
1594 : : default:
1595 : : return false;
1596 : : }
1597 : : }
1598 : :
1599 : : /* Try to evaluate:
1600 : :
1601 : : *RESULT = FN (ARG0, ARG1)
1602 : :
1603 : : where ARG_TYPE is the type of ARG0 and PRECISION is the number of bits in
1604 : : the result. Return true on success. */
1605 : :
1606 : : static bool
1607 : 167992 : fold_const_call_sss (wide_int *result, combined_fn fn,
1608 : : const wide_int_ref &arg0, const wide_int_ref &arg1,
1609 : : unsigned int precision, tree arg_type ATTRIBUTE_UNUSED)
1610 : : {
1611 : 167992 : switch (fn)
1612 : : {
1613 : 10385 : case CFN_CLZ:
1614 : 10385 : case CFN_BUILT_IN_CLZG:
1615 : 10385 : {
1616 : 10385 : int tmp;
1617 : 10385 : if (wi::ne_p (arg0, 0))
1618 : 10237 : tmp = wi::clz (arg0);
1619 : : else
1620 : 148 : tmp = arg1.to_shwi ();
1621 : 10385 : *result = wi::shwi (tmp, precision);
1622 : 10385 : return true;
1623 : : }
1624 : :
1625 : 5033 : case CFN_CTZ:
1626 : 5033 : case CFN_BUILT_IN_CTZG:
1627 : 5033 : {
1628 : 5033 : int tmp;
1629 : 5033 : if (wi::ne_p (arg0, 0))
1630 : 4929 : tmp = wi::ctz (arg0);
1631 : : else
1632 : 104 : tmp = arg1.to_shwi ();
1633 : 5033 : *result = wi::shwi (tmp, precision);
1634 : 5033 : return true;
1635 : : }
1636 : :
1637 : : default:
1638 : : return false;
1639 : : }
1640 : : }
1641 : :
1642 : : /* Try to evaluate:
1643 : :
1644 : : RESULT = fn (ARG0, ARG1)
1645 : :
1646 : : where FORMAT is the format of the real and imaginary parts of RESULT
1647 : : (RESULT_REAL and RESULT_IMAG), of ARG0 (ARG0_REAL and ARG0_IMAG)
1648 : : and of ARG1 (ARG1_REAL and ARG1_IMAG). Return true on success. */
1649 : :
1650 : : static bool
1651 : 32067 : fold_const_call_ccc (real_value *result_real, real_value *result_imag,
1652 : : combined_fn fn, const real_value *arg0_real,
1653 : : const real_value *arg0_imag, const real_value *arg1_real,
1654 : : const real_value *arg1_imag, const real_format *format)
1655 : : {
1656 : 0 : switch (fn)
1657 : : {
1658 : 32067 : CASE_CFN_CPOW:
1659 : 32067 : CASE_CFN_CPOW_FN:
1660 : 32067 : return do_mpc_arg2 (result_real, result_imag, mpc_pow,
1661 : 0 : arg0_real, arg0_imag, arg1_real, arg1_imag, format);
1662 : :
1663 : : default:
1664 : : return false;
1665 : : }
1666 : : }
1667 : :
1668 : : /* Subroutine of fold_const_call, with the same interface. Handle cases
1669 : : where the arguments and result are numerical. */
1670 : :
1671 : : static tree
1672 : 14270770 : fold_const_call_1 (combined_fn fn, tree type, tree arg0, tree arg1)
1673 : : {
1674 : 14270770 : machine_mode mode = TYPE_MODE (type);
1675 : 14270770 : machine_mode arg0_mode = TYPE_MODE (TREE_TYPE (arg0));
1676 : 14270770 : machine_mode arg1_mode = TYPE_MODE (TREE_TYPE (arg1));
1677 : :
1678 : 14270770 : if (integer_cst_p (arg0) && integer_cst_p (arg1))
1679 : : {
1680 : 173695 : if (SCALAR_INT_MODE_P (mode))
1681 : : {
1682 : 167992 : wide_int result;
1683 : 167992 : if (fold_const_call_sss (&result, fn, wi::to_wide (arg0),
1684 : 335984 : wi::to_wide (arg1), TYPE_PRECISION (type),
1685 : 167992 : TREE_TYPE (arg0)))
1686 : 15418 : return wide_int_to_tree (type, result);
1687 : 167992 : }
1688 : 158277 : return NULL_TREE;
1689 : : }
1690 : :
1691 : 14097075 : if (mode == arg0_mode
1692 : 9418590 : && real_cst_p (arg0)
1693 : 15362398 : && real_cst_p (arg1))
1694 : : {
1695 : 233619 : gcc_checking_assert (SCALAR_FLOAT_MODE_P (arg0_mode));
1696 : 233619 : REAL_VALUE_TYPE result;
1697 : 233619 : if (arg0_mode == arg1_mode)
1698 : : {
1699 : : /* real, real -> real. */
1700 : 466658 : if (fold_const_call_sss (&result, fn, TREE_REAL_CST_PTR (arg0),
1701 : 233329 : TREE_REAL_CST_PTR (arg1),
1702 : 233329 : REAL_MODE_FORMAT (mode)))
1703 : 198872 : return build_real (type, result);
1704 : : }
1705 : 290 : else if (arg1_mode == TYPE_MODE (long_double_type_node))
1706 : 290 : switch (fn)
1707 : : {
1708 : 290 : CASE_CFN_NEXTTOWARD:
1709 : : /* real, long double -> real. */
1710 : 580 : if (fold_const_call_sss (&result, fn, TREE_REAL_CST_PTR (arg0),
1711 : 290 : TREE_REAL_CST_PTR (arg1),
1712 : 290 : REAL_MODE_FORMAT (mode)))
1713 : 228 : return build_real (type, result);
1714 : : break;
1715 : : default:
1716 : : break;
1717 : : }
1718 : 34519 : return NULL_TREE;
1719 : : }
1720 : :
1721 : 13863456 : if (real_cst_p (arg0)
1722 : 13863456 : && integer_cst_p (arg1))
1723 : : {
1724 : 25651 : gcc_checking_assert (SCALAR_FLOAT_MODE_P (arg0_mode));
1725 : 25651 : if (mode == arg0_mode)
1726 : : {
1727 : : /* real, int -> real. */
1728 : 25648 : REAL_VALUE_TYPE result;
1729 : 25648 : if (fold_const_call_sss (&result, fn, TREE_REAL_CST_PTR (arg0),
1730 : 51296 : wi::to_wide (arg1),
1731 : 25648 : REAL_MODE_FORMAT (mode)))
1732 : 5501 : return build_real (type, result);
1733 : : }
1734 : 20150 : return NULL_TREE;
1735 : : }
1736 : :
1737 : 13837805 : if (integer_cst_p (arg0)
1738 : 13837805 : && real_cst_p (arg1))
1739 : : {
1740 : 6422 : gcc_checking_assert (SCALAR_FLOAT_MODE_P (arg1_mode));
1741 : 6422 : if (mode == arg1_mode)
1742 : : {
1743 : : /* int, real -> real. */
1744 : 6422 : REAL_VALUE_TYPE result;
1745 : 12844 : if (fold_const_call_sss (&result, fn, wi::to_wide (arg0),
1746 : 6422 : TREE_REAL_CST_PTR (arg1),
1747 : 6422 : REAL_MODE_FORMAT (mode)))
1748 : 1743 : return build_real (type, result);
1749 : : }
1750 : 4679 : return NULL_TREE;
1751 : : }
1752 : :
1753 : 13831383 : if (arg0_mode == arg1_mode
1754 : 11226319 : && complex_cst_p (arg0)
1755 : 13863450 : && complex_cst_p (arg1))
1756 : : {
1757 : 32067 : gcc_checking_assert (COMPLEX_MODE_P (arg0_mode));
1758 : 32067 : machine_mode inner_mode = GET_MODE_INNER (arg0_mode);
1759 : 32067 : tree arg0r = TREE_REALPART (arg0);
1760 : 32067 : tree arg0i = TREE_IMAGPART (arg0);
1761 : 32067 : tree arg1r = TREE_REALPART (arg1);
1762 : 32067 : tree arg1i = TREE_IMAGPART (arg1);
1763 : 32067 : if (mode == arg0_mode
1764 : 32067 : && real_cst_p (arg0r)
1765 : 32067 : && real_cst_p (arg0i)
1766 : 32067 : && real_cst_p (arg1r)
1767 : 64134 : && real_cst_p (arg1i))
1768 : : {
1769 : : /* complex real, complex real -> complex real. */
1770 : 32067 : REAL_VALUE_TYPE result_real, result_imag;
1771 : 64134 : if (fold_const_call_ccc (&result_real, &result_imag, fn,
1772 : 32067 : TREE_REAL_CST_PTR (arg0r),
1773 : 32067 : TREE_REAL_CST_PTR (arg0i),
1774 : 32067 : TREE_REAL_CST_PTR (arg1r),
1775 : 32067 : TREE_REAL_CST_PTR (arg1i),
1776 : 32067 : REAL_MODE_FORMAT (inner_mode)))
1777 : 21470 : return build_complex (type,
1778 : 10735 : build_real (TREE_TYPE (type), result_real),
1779 : 21470 : build_real (TREE_TYPE (type), result_imag));
1780 : : }
1781 : 21332 : return NULL_TREE;
1782 : : }
1783 : :
1784 : : return NULL_TREE;
1785 : : }
1786 : :
1787 : : /* Try to fold FN (ARG0, ARG1) to a constant. Return the constant on success,
1788 : : otherwise return null. TYPE is the type of the return value. */
1789 : :
1790 : : tree
1791 : 16936170 : fold_const_call (combined_fn fn, tree type, tree arg0, tree arg1)
1792 : : {
1793 : 16936170 : const char *p0, *p1;
1794 : 16936170 : char c;
1795 : 16936170 : tree_code subcode;
1796 : 16936170 : switch (fn)
1797 : : {
1798 : 2692 : case CFN_BUILT_IN_STRSPN:
1799 : 2692 : if ((p0 = c_getstr (arg0)) && (p1 = c_getstr (arg1)))
1800 : 123 : return build_int_cst (type, strspn (p0, p1));
1801 : : return NULL_TREE;
1802 : :
1803 : 2596 : case CFN_BUILT_IN_STRCSPN:
1804 : 2596 : if ((p0 = c_getstr (arg0)) && (p1 = c_getstr (arg1)))
1805 : 123 : return build_int_cst (type, strcspn (p0, p1));
1806 : : return NULL_TREE;
1807 : :
1808 : 2207055 : case CFN_BUILT_IN_STRCMP:
1809 : 2207055 : if ((p0 = c_getstr (arg0)) && (p1 = c_getstr (arg1)))
1810 : 24183 : return build_cmp_result (type, strcmp (p0, p1));
1811 : : return NULL_TREE;
1812 : :
1813 : 251 : case CFN_BUILT_IN_STRCASECMP:
1814 : 251 : if ((p0 = c_getstr (arg0)) && (p1 = c_getstr (arg1)))
1815 : : {
1816 : 7 : int r = strcmp (p0, p1);
1817 : 7 : if (r == 0)
1818 : 1 : return build_cmp_result (type, r);
1819 : : }
1820 : : return NULL_TREE;
1821 : :
1822 : 176509 : case CFN_BUILT_IN_INDEX:
1823 : 176509 : case CFN_BUILT_IN_STRCHR:
1824 : 176509 : if ((p0 = c_getstr (arg0)) && target_char_cst_p (arg1, &c))
1825 : : {
1826 : 136 : const char *r = strchr (p0, c);
1827 : 136 : if (r == NULL)
1828 : 32 : return build_int_cst (type, 0);
1829 : 104 : return fold_convert (type,
1830 : : fold_build_pointer_plus_hwi (arg0, r - p0));
1831 : : }
1832 : : return NULL_TREE;
1833 : :
1834 : 166629 : case CFN_BUILT_IN_RINDEX:
1835 : 166629 : case CFN_BUILT_IN_STRRCHR:
1836 : 166629 : if ((p0 = c_getstr (arg0)) && target_char_cst_p (arg1, &c))
1837 : : {
1838 : 103 : const char *r = strrchr (p0, c);
1839 : 103 : if (r == NULL)
1840 : 35 : return build_int_cst (type, 0);
1841 : 68 : return fold_convert (type,
1842 : : fold_build_pointer_plus_hwi (arg0, r - p0));
1843 : : }
1844 : : return NULL_TREE;
1845 : :
1846 : 91616 : case CFN_BUILT_IN_STRSTR:
1847 : 91616 : if ((p1 = c_getstr (arg1)))
1848 : : {
1849 : 6055 : if ((p0 = c_getstr (arg0)))
1850 : : {
1851 : 182 : const char *r = strstr (p0, p1);
1852 : 182 : if (r == NULL)
1853 : 38 : return build_int_cst (type, 0);
1854 : 144 : return fold_convert (type,
1855 : : fold_build_pointer_plus_hwi (arg0, r - p0));
1856 : : }
1857 : 5873 : if (*p1 == '\0')
1858 : 13 : return fold_convert (type, arg0);
1859 : : }
1860 : : return NULL_TREE;
1861 : :
1862 : 0 : case CFN_FOLD_LEFT_PLUS:
1863 : 0 : return fold_const_fold_left (type, arg0, arg1, PLUS_EXPR);
1864 : :
1865 : 0 : case CFN_VEC_SHL_INSERT:
1866 : 0 : return fold_const_vec_shl_insert (type, arg0, arg1);
1867 : :
1868 : 6390 : case CFN_UBSAN_CHECK_ADD:
1869 : 6390 : case CFN_ADD_OVERFLOW:
1870 : 6390 : subcode = PLUS_EXPR;
1871 : 6390 : goto arith_overflow;
1872 : :
1873 : 6299 : case CFN_UBSAN_CHECK_SUB:
1874 : 6299 : case CFN_SUB_OVERFLOW:
1875 : 6299 : subcode = MINUS_EXPR;
1876 : 6299 : goto arith_overflow;
1877 : :
1878 : 5363 : case CFN_UBSAN_CHECK_MUL:
1879 : 5363 : case CFN_MUL_OVERFLOW:
1880 : 5363 : subcode = MULT_EXPR;
1881 : 5363 : goto arith_overflow;
1882 : :
1883 : 18052 : arith_overflow:
1884 : 18052 : if (integer_cst_p (arg0) && integer_cst_p (arg1))
1885 : : {
1886 : 17163 : tree itype
1887 : 17163 : = TREE_CODE (type) == COMPLEX_TYPE ? TREE_TYPE (type) : type;
1888 : 17163 : bool ovf = false;
1889 : 17163 : tree r = int_const_binop (subcode, fold_convert (itype, arg0),
1890 : 17163 : fold_convert (itype, arg1));
1891 : 17163 : if (!r || TREE_CODE (r) != INTEGER_CST)
1892 : : return NULL_TREE;
1893 : 17163 : if (arith_overflowed_p (subcode, itype, arg0, arg1))
1894 : : ovf = true;
1895 : 17163 : if (TREE_OVERFLOW (r))
1896 : 3402 : r = drop_tree_overflow (r);
1897 : 17163 : if (itype == type)
1898 : : {
1899 : 2701 : if (ovf)
1900 : : return NULL_TREE;
1901 : : return r;
1902 : : }
1903 : : else
1904 : 14462 : return build_complex (type, r, build_int_cst (itype, ovf));
1905 : : }
1906 : : return NULL_TREE;
1907 : :
1908 : 14270770 : default:
1909 : 14270770 : return fold_const_call_1 (fn, type, arg0, arg1);
1910 : : }
1911 : : }
1912 : :
1913 : : /* Try to evaluate:
1914 : :
1915 : : *RESULT = FN (*ARG0, *ARG1, *ARG2)
1916 : :
1917 : : in format FORMAT. Return true on success. */
1918 : :
1919 : : static bool
1920 : 2534 : fold_const_call_ssss (real_value *result, combined_fn fn,
1921 : : const real_value *arg0, const real_value *arg1,
1922 : : const real_value *arg2, const real_format *format)
1923 : : {
1924 : 2534 : switch (fn)
1925 : : {
1926 : 2534 : CASE_CFN_FMA:
1927 : 2534 : CASE_CFN_FMA_FN:
1928 : 2534 : return do_mpfr_arg3 (result, mpfr_fma, arg0, arg1, arg2, format);
1929 : :
1930 : 0 : case CFN_FMS:
1931 : 0 : {
1932 : 0 : real_value new_arg2 = real_value_negate (arg2);
1933 : 0 : return do_mpfr_arg3 (result, mpfr_fma, arg0, arg1, &new_arg2, format);
1934 : : }
1935 : :
1936 : 0 : case CFN_FNMA:
1937 : 0 : {
1938 : 0 : real_value new_arg0 = real_value_negate (arg0);
1939 : 0 : return do_mpfr_arg3 (result, mpfr_fma, &new_arg0, arg1, arg2, format);
1940 : : }
1941 : :
1942 : 0 : case CFN_FNMS:
1943 : 0 : {
1944 : 0 : real_value new_arg0 = real_value_negate (arg0);
1945 : 0 : real_value new_arg2 = real_value_negate (arg2);
1946 : 0 : return do_mpfr_arg3 (result, mpfr_fma, &new_arg0, arg1,
1947 : : &new_arg2, format);
1948 : : }
1949 : :
1950 : : default:
1951 : : return false;
1952 : : }
1953 : : }
1954 : :
1955 : : /* Subroutine of fold_const_call, with the same interface. Handle cases
1956 : : where the arguments and result are numerical. */
1957 : :
1958 : : static tree
1959 : 3614571 : fold_const_call_1 (combined_fn fn, tree type, tree arg0, tree arg1, tree arg2)
1960 : : {
1961 : 3614571 : machine_mode mode = TYPE_MODE (type);
1962 : 3614571 : machine_mode arg0_mode = TYPE_MODE (TREE_TYPE (arg0));
1963 : 3614571 : machine_mode arg1_mode = TYPE_MODE (TREE_TYPE (arg1));
1964 : 3614571 : machine_mode arg2_mode = TYPE_MODE (TREE_TYPE (arg2));
1965 : :
1966 : 3614571 : if (arg0_mode == arg1_mode
1967 : 3614571 : && arg0_mode == arg2_mode
1968 : 1403090 : && real_cst_p (arg0)
1969 : 2654 : && real_cst_p (arg1)
1970 : 3617153 : && real_cst_p (arg2))
1971 : : {
1972 : 2534 : gcc_checking_assert (SCALAR_FLOAT_MODE_P (arg0_mode));
1973 : 2534 : if (mode == arg0_mode)
1974 : : {
1975 : : /* real, real, real -> real. */
1976 : 2534 : REAL_VALUE_TYPE result;
1977 : 5068 : if (fold_const_call_ssss (&result, fn, TREE_REAL_CST_PTR (arg0),
1978 : 2534 : TREE_REAL_CST_PTR (arg1),
1979 : 2534 : TREE_REAL_CST_PTR (arg2),
1980 : 2534 : REAL_MODE_FORMAT (mode)))
1981 : 1060 : return build_real (type, result);
1982 : : }
1983 : 1474 : return NULL_TREE;
1984 : : }
1985 : :
1986 : : return NULL_TREE;
1987 : : }
1988 : :
1989 : : /* Try to fold FN (ARG0, ARG1, ARG2) to a constant. Return the constant on
1990 : : success, otherwise return null. TYPE is the type of the return value. */
1991 : :
1992 : : tree
1993 : 6255025 : fold_const_call (combined_fn fn, tree type, tree arg0, tree arg1, tree arg2)
1994 : : {
1995 : 6255025 : const char *p0, *p1;
1996 : 6255025 : char c;
1997 : 6255025 : unsigned HOST_WIDE_INT s0, s1, s2 = 0;
1998 : 6255025 : switch (fn)
1999 : : {
2000 : 44954 : case CFN_BUILT_IN_STRNCMP:
2001 : 44954 : if (!size_t_cst_p (arg2, &s2))
2002 : : return NULL_TREE;
2003 : 28948 : if (s2 == 0
2004 : 237 : && !TREE_SIDE_EFFECTS (arg0)
2005 : 29157 : && !TREE_SIDE_EFFECTS (arg1))
2006 : 209 : return build_int_cst (type, 0);
2007 : 28739 : else if ((p0 = c_getstr (arg0)) && (p1 = c_getstr (arg1)))
2008 : 573 : return build_int_cst (type, strncmp (p0, p1, MIN (s2, SIZE_MAX)));
2009 : : return NULL_TREE;
2010 : :
2011 : 7999 : case CFN_BUILT_IN_STRNCASECMP:
2012 : 7999 : if (!size_t_cst_p (arg2, &s2))
2013 : : return NULL_TREE;
2014 : 7678 : if (s2 == 0
2015 : 9 : && !TREE_SIDE_EFFECTS (arg0)
2016 : 7683 : && !TREE_SIDE_EFFECTS (arg1))
2017 : 5 : return build_int_cst (type, 0);
2018 : 7673 : else if ((p0 = c_getstr (arg0))
2019 : 724 : && (p1 = c_getstr (arg1))
2020 : 7813 : && strncmp (p0, p1, MIN (s2, SIZE_MAX)) == 0)
2021 : 3 : return build_int_cst (type, 0);
2022 : : return NULL_TREE;
2023 : :
2024 : 2409720 : case CFN_BUILT_IN_BCMP:
2025 : 2409720 : case CFN_BUILT_IN_MEMCMP:
2026 : 2409720 : if (!size_t_cst_p (arg2, &s2))
2027 : : return NULL_TREE;
2028 : 1537392 : if (s2 == 0
2029 : 13022 : && !TREE_SIDE_EFFECTS (arg0)
2030 : 1550414 : && !TREE_SIDE_EFFECTS (arg1))
2031 : 13022 : return build_int_cst (type, 0);
2032 : 1524370 : if ((p0 = getbyterep (arg0, &s0))
2033 : 12119 : && (p1 = getbyterep (arg1, &s1))
2034 : 3817 : && s2 <= s0
2035 : 1527727 : && s2 <= s1)
2036 : 3355 : return build_cmp_result (type, memcmp (p0, p1, s2));
2037 : : return NULL_TREE;
2038 : :
2039 : 177689 : case CFN_BUILT_IN_MEMCHR:
2040 : 177689 : if (!size_t_cst_p (arg2, &s2))
2041 : : return NULL_TREE;
2042 : 7136 : if (s2 == 0
2043 : 150 : && !TREE_SIDE_EFFECTS (arg0)
2044 : 7269 : && !TREE_SIDE_EFFECTS (arg1))
2045 : 130 : return build_int_cst (type, 0);
2046 : 7006 : if ((p0 = getbyterep (arg0, &s0))
2047 : 1983 : && s2 <= s0
2048 : 8870 : && target_char_cst_p (arg1, &c))
2049 : : {
2050 : 690 : const char *r = (const char *) memchr (p0, c, s2);
2051 : 690 : if (r == NULL)
2052 : 268 : return build_int_cst (type, 0);
2053 : 422 : return fold_convert (type,
2054 : : fold_build_pointer_plus_hwi (arg0, r - p0));
2055 : : }
2056 : : return NULL_TREE;
2057 : :
2058 : 0 : case CFN_WHILE_ULT:
2059 : 0 : {
2060 : 0 : poly_uint64 parg0, parg1;
2061 : 0 : if (poly_int_tree_p (arg0, &parg0) && poly_int_tree_p (arg1, &parg1))
2062 : 0 : return fold_while_ult (type, parg0, parg1);
2063 : : return NULL_TREE;
2064 : : }
2065 : :
2066 : 92 : case CFN_UADDC:
2067 : 92 : case CFN_USUBC:
2068 : 92 : if (integer_cst_p (arg0) && integer_cst_p (arg1) && integer_cst_p (arg2))
2069 : : {
2070 : 92 : tree itype = TREE_TYPE (type);
2071 : 92 : bool ovf = false;
2072 : 92 : tree_code subcode = fn == CFN_UADDC ? PLUS_EXPR : MINUS_EXPR;
2073 : 92 : tree r = int_const_binop (subcode, fold_convert (itype, arg0),
2074 : 92 : fold_convert (itype, arg1));
2075 : 92 : if (!r)
2076 : : return NULL_TREE;
2077 : 92 : if (arith_overflowed_p (subcode, itype, arg0, arg1))
2078 : : ovf = true;
2079 : 92 : tree r2 = int_const_binop (subcode, r, fold_convert (itype, arg2));
2080 : 92 : if (!r2 || TREE_CODE (r2) != INTEGER_CST)
2081 : : return NULL_TREE;
2082 : 92 : if (arith_overflowed_p (subcode, itype, r, arg2))
2083 : 0 : ovf = true;
2084 : 92 : if (TREE_OVERFLOW (r2))
2085 : 0 : r2 = drop_tree_overflow (r2);
2086 : 92 : return build_complex (type, r2, build_int_cst (itype, ovf));
2087 : : }
2088 : : return NULL_TREE;
2089 : :
2090 : 3614571 : default:
2091 : 3614571 : return fold_const_call_1 (fn, type, arg0, arg1, arg2);
2092 : : }
2093 : : }
|