summaryrefslogtreecommitdiff
path: root/gcc/fold-const-call.c
Commit message (Collapse)AuthorAgeFilesLines
* * builtins.c (fold_builtin_strstr): Removed.jakub2016-12-071-0/+16
| | | | | | | | | | | | | | | (fold_builtin_2): Don't call fold_builtin_strstr. * gimple-fold.c (gimple_fold_builtin_strchr): Check is_strrchr earlier in the strrchr (x, 0) -> strchr (x, 0) optimization. (gimple_fold_builtin_strstr): New function. (gimple_fold_builtin): Call it. * fold-const-call.c (fold_const_call): Handle CFN_BUILT_IN_STRSTR. * gcc.dg/builtin-strstr-1.c: New test. * g++.dg/cpp0x/constexpr-strstr.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@243378 138bc75d-0d04-0410-961f-82ee72b054a4
* 2016-12-06 Jakub Jelinek <jakub@redhat.com>jakub2016-12-061-54/+46
| | | | | | | | | | | | | | | PR c++/71537 * fold-const-call.c (fold_const_call_1): Remove memchr handling here. (fold_const_call) <case CFN_BUILT_IN_STRNCMP, case CFN_BUILT_IN_STRNCASECMP>: Formatting improvements. (fold_const_call) <case CFN_BUILT_IN_MEMCMP>: Likewise. If s2 is 0 and arguments have no side-effects, return 0. (fold_const_call): Handle CFN_BUILT_IN_MEMCHR. * g++.dg/cpp0x/constexpr-memchr.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@243285 138bc75d-0d04-0410-961f-82ee72b054a4
* PR c++/71537jakub2016-12-061-0/+25
| | | | | | | | | | * fold-const-call.c (fold_const_call): Handle CFN_BUILT_IN_{INDEX,STRCHR,RINDEX,STRRCHR}. * g++.dg/cpp0x/constexpr-strchr.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@243284 138bc75d-0d04-0410-961f-82ee72b054a4
* * fold-const-call.c (fold_const_call): Fix up type of s0 and s1.jakub2016-11-091-1/+2
| | | | git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@242011 138bc75d-0d04-0410-961f-82ee72b054a4
* Fix folding of memcmp("a", "a", 2) (PRmarxin2016-11-091-5/+5
| | | | | | | | | | * fold-const-call.c (fold_const_call): Fix the folding. * gcc.dg/tree-ssa/builtins-folding-generic.c (main): Add new test-case for memcmp. * gcc.dg/tree-ssa/builtins-folding-gimple.c: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@242000 138bc75d-0d04-0410-961f-82ee72b054a4
* Fix host_size_t_cst_p predicatmarxin2016-11-021-1/+3
| | | | | | | | | | * fold-const-call.c (host_size_t_cst_p): Test whether t is convertible to size_t. * gcc.dg/tree-ssa/builtins-folding-gimple-ub.c (main): Add test case. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@241780 138bc75d-0d04-0410-961f-82ee72b054a4
* Fold __builtin_memchr functionmarxin2016-10-141-0/+31
| | | | | | | | | | | | | * builtins.h(target_char_cst_p): Declare the function. * builtins.c (fold_builtin_memchr): Remove. (target_char_cst_p): Move the function from gimple-fold.c. (fold_builtin_3): Do not call the function. * gimple-fold.c (gimple_fold_builtin_memchr): New function. (gimple_fold_builtin): Call the function. * fold-const-call.c (fold_const_call_1): Handle CFN_BUILT_IN_MEMCHR. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@241160 138bc75d-0d04-0410-961f-82ee72b054a4
* Fold __builtin_str{n}{case}cmp functionsmarxin2016-10-141-8/+37
| | | | | | | | | | | | | | | | * builtins.c (fold_builtin_strcmp): Remove function. (fold_builtin_strncmp): Likewise. (fold_builtin_2): Remove call of the function. (fold_builtin_3): Likewise. * fold-const-call.c (fold_const_call): Add constant folding for CFN_BUILT_IN_STRCASECMP and CFN_BUILT_IN_STRNCASECMP. * fold-const-call.h (build_cmp_result): Declare the function. * gimple-fold.c (gimple_load_first_char): New function. (gimple_fold_builtin_string_compare): Likewise. (gimple_fold_builtin): Call the function. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@241159 138bc75d-0d04-0410-961f-82ee72b054a4
* Add minimal _FloatN, _FloatNx built-in functions.jsm282016-08-221-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds a minimal set of built-in functions for the new _FloatN and _FloatNx types. The functions added are __builtin_fabs*, __builtin_copysign*, __builtin_huge_val*, __builtin_inf*, __builtin_nan* and __builtin_nans* (where * = fN or fNx). That is, 42 new entries are added to the enum of built-in functions and the associated array of decls, where not all of them are actually supported on any one target. These functions are believed to be sufficient for libgcc (complex multiplication and division use __builtin_huge_val*, __builtin_copysign* and __builtin_fabs*) and for glibc (which also depends on complex multiplication from libgcc, as well as using such functions itself). The basic target-independent support for folding / expanding calls to these built-in functions is wired up, so those for constants can be used in static initializers, and the fabs and copysign built-ins can always be expanded to bit-manipulation inline (for any format setting signbit_ro and signbit_rw, which covers all formats supported for _FloatN and _FloatNx), although insn patterns for fabs (abs<mode>2) and copysign (copysign<mode>3) will be used when available and may result in more optimal code. The complex multiplication and division functions in libgcc rely on predefined macros (defined with -fbuilding-libgcc) to say what the built-in function suffixes to use with a particular mode are. This patch updates that code accordingly, where previously it involved a hack supposing that machine-specific suffixes for constants were also suffixes for built-in functions. As with the main _FloatN / _FloatNx patch, this patch does not update code dealing only with optimizations that currently has cases only covering float, double and long double, though some such cases are straightforward and may be covered in a followup patch. The functions are defined with DEF_GCC_BUILTIN, so calls to the TS 18661-3 functions such as fabsf128 and copysignf128, without the __builtin_, will not be optimized. As noted in the original _FloatN / _FloatNx patch submission, in principle the bulk of the libm functions that have built-in versions should have those versions extended to cover the new types, but that would require more consideration of the effects of increasing the size of the enum and initializing many more functions at startup. I don't know whether target-specific built-in functions can readily be made into aliases for target-independent functions, but if they can, it would make sense to do so for the x86, ia64 and rs6000 *q functions corresponding to these, so that they can benefit from the architecture-independent folding logic and from any optimizations enabled for these functions in future, and so that less target-specific code is needed to support them. Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc: * tree.h (CASE_FLT_FN_FLOATN_NX, float16_type_node) (float32_type_node, float64_type_node, float32x_type_node) (float128x_type_node): New macros. * builtin-types.def (BT_FLOAT16, BT_FLOAT32, BT_FLOAT64) (BT_FLOAT128, BT_FLOAT32X, BT_FLOAT64X, BT_FLOAT128X) (BT_FN_FLOAT16, BT_FN_FLOAT32, BT_FN_FLOAT64, BT_FN_FLOAT128) (BT_FN_FLOAT32X, BT_FN_FLOAT64X, BT_FN_FLOAT128X) (BT_FN_FLOAT16_FLOAT16, BT_FN_FLOAT32_FLOAT32) (BT_FN_FLOAT64_FLOAT64, BT_FN_FLOAT128_FLOAT128) (BT_FN_FLOAT32X_FLOAT32X, BT_FN_FLOAT64X_FLOAT64X) (BT_FN_FLOAT128X_FLOAT128X, BT_FN_FLOAT16_CONST_STRING) (BT_FN_FLOAT32_CONST_STRING, BT_FN_FLOAT64_CONST_STRING) (BT_FN_FLOAT128_CONST_STRING, BT_FN_FLOAT32X_CONST_STRING) (BT_FN_FLOAT64X_CONST_STRING, BT_FN_FLOAT128X_CONST_STRING) (BT_FN_FLOAT16_FLOAT16_FLOAT16, BT_FN_FLOAT32_FLOAT32_FLOAT32) (BT_FN_FLOAT64_FLOAT64_FLOAT64, BT_FN_FLOAT128_FLOAT128_FLOAT128) (BT_FN_FLOAT32X_FLOAT32X_FLOAT32X) (BT_FN_FLOAT64X_FLOAT64X_FLOAT64X) (BT_FN_FLOAT128X_FLOAT128X_FLOAT128X): New type definitions. * builtins.def (DEF_GCC_FLOATN_NX_BUILTINS): New macro. (copysign, fabs, huge_val, inf, nan, nans): Use it. * builtins.c (expand_builtin): Use CASE_FLT_FN_FLOATN_NX for fabs and copysign. (fold_builtin_0): Use CASE_FLT_FN_FLOATN_NX for inf and huge_val. (fold_builtin_1): Use CASE_FLT_FN_FLOATN_NX for fabs. * doc/extend.texi (Other Builtins): Document these built-in functions. * fold-const-call.c (fold_const_call): Use CASE_FLT_FN_FLOATN_NX for nan and nans. gcc/c-family: * c-family/c-cppbuiltin.c (c_cpp_builtins): Check _FloatN and _FloatNx types for suffixes for built-in functions. gcc/testsuite: * gcc.dg/torture/float128-builtin.c, gcc.dg/torture/float128-ieee-nan.c, gcc.dg/torture/float128x-builtin.c, gcc.dg/torture/float128x-nan.c, gcc.dg/torture/float16-builtin.c, gcc.dg/torture/float16-nan.c, gcc.dg/torture/float32-builtin.c, gcc.dg/torture/float32-nan.c, gcc.dg/torture/float32x-builtin.c, gcc.dg/torture/float32x-nan.c, gcc.dg/torture/float64-builtin.c, gcc.dg/torture/float64-nan.c, gcc.dg/torture/float64x-builtin.c, gcc.dg/torture/float64x-nan.c, gcc.dg/torture/floatn-builtin.h, gcc.dg/torture/floatn-nan.h: New tests. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@239658 138bc75d-0d04-0410-961f-82ee72b054a4
* Update copyright years.jakub2016-01-041-1/+1
| | | | git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@232055 138bc75d-0d04-0410-961f-82ee72b054a4
* This series of patches fix PR61441. This patch avoids various transformationsssaraswati2015-12-221-1/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | with signaling NaN operands when flag_signaling_nans is on, to avoid folding which would lose exceptions. Bootstrapped & regression-tested on x86_64-linux-gnu. gcc/ * fold-const.c (const_binop): Convert sNaN to qNaN when flag_signaling_nans is off. (const_unop): Avoid the operation, other than NEGATE and ABS, if flag_signaling_nans is on and the operand is an sNaN. (fold_convert_const_real_from_real): Avoid the operation if flag_signaling_nans is on and the operand is an sNaN. (integer_valued_real_unary_p): Update comment stating it returns false for sNaN values. (integer_valued_real_binary_p, integer_valued_real_call_p): Same. (integer_valued_real_single_p): Same. (integer_valued_real_invalid_p, integer_valued_real_p): Same. * fold-const-call.c (fold_const_pow): Avoid the operation if flag_signaling_nans is on and the operand is an sNaN. (fold_const_builtin_load_exponent) Same. (fold_const_call_sss): Same for CASE_CFN_POWI. * gimple-fold.c (gimple_assign_integer_valued_real_p): Same. (gimple_call_integer_valued_real_p): Same. (gimple_phi_integer_valued_real_p): Same. (gimple_stmt_integer_valued_real_p): Same. * simplify-rtx.c (simplify_const_unary_operation): Avoid the operation if flag_signaling_nans is on and the operand is an sNaN. (simplify_const_binary_operation): Same. * tree-ssa-math-opts.c (gimple_expand_builtin_pow): Avoid the operation if flag_signaling_nans is on and the operand is an sNaN. * gcc.dg/pr61441.c: New testcase. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@231901 138bc75d-0d04-0410-961f-82ee72b054a4
* Extend fold_const_call to combined_fnrsandifo2015-11-171-140/+138
| | | | | | | | | | | | | | | | | | | | | This patch extends fold_const_call so that it can handle internal as well as built-in functions. Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. gcc/ * fold-const-call.h (fold_const_call): Replace built_in_function arguments with combined_fn arguments. * fold-const-call.c: Include case-cfn-macros.h. (fold_const_call_ss, fold_const_call_cs, fold_const_call_sc) (fold_const_call_cc, fold_const_call_sss, fold_const_call_ccc) (fold_const_call_ssss, fold_const_call_1, fold_const_call): Replace built_in_function arguments with combined_fn arguments. * builtins.c (fold_builtin_sincos, fold_builtin_1, fold_builtin_2) (fold_builtin_3): Update calls to fold_const_call. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@230477 138bc75d-0d04-0410-961f-82ee72b054a4
* Move const char * -> int/fp folds to fold-const-call.crsandifo2015-11-071-13/+142
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch moves folds that deal with constant string arguments and return a constant integer or floating-point value. For example, it handles strcmp ("foo", "bar") but not strstr ("foobar", "bar"), which wouldn't currently be accepted by the gimple folders. The builtins.c folding for strlen (via c_strlen) is a bit more general than what the fold-const-call.c code does (and more general than we need for the gimple folders). I've therefore left it as-is, even though it partially duplicates the new code. Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. gcc/ * builtins.c (fold_builtin_nan): Delete. (fold_builtin_memcmp): Remove case where both arguments are constant. (fold_builtin_strcmp, fold_builtin_strncmp): Likewise. (fold_builtin_strspn, fold_builtin_strcspn): Likewise. (fold_builtin_1): Remove BUILT_IN_NAN* handling. * fold-const-call.c: Include fold-const.h. (host_size_t_cst_p): New function. (build_cmp_result, fold_const_builtin_nan): Likewise. (fold_const_call_1): New function, split out from... (fold_const_call): ...here (for all three interfaces). Handle constant nan, nans, strlen, strcmp, strncmp, strspn and strcspn. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229922 138bc75d-0d04-0410-961f-82ee72b054a4
* Move constant bitop and bswap folds to fold-const-call.crsandifo2015-11-071-0/+76
| | | | | | | | | | | | | | | | | The only folds left in builtins.c were for constants, so we can remove the builtins.c handling entirely. Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. gcc/ * builtins.c (fold_builtin_bitop, fold_builtin_bswap): Delete. (fold_builtin_1): Don't call them. * fold-const-call.c: Include tm.h. (fold_const_call_ss): New variant for integer-to-integer folds. (fold_const_call): Call it. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229921 138bc75d-0d04-0410-961f-82ee72b054a4
* Handle constant fp classifications in fold-const-call.crsandifo2015-11-071-0/+25
| | | | | | | | | | | | | | Move the constant "is finite", "is infinite" and "is nan" queries to fold-const-call.c. Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. gcc/ * builtins.c (fold_builtin_classify): Move constant cases to... * fold-const-call.c (fold_const_call_ss): ...here. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229920 138bc75d-0d04-0410-961f-82ee72b054a4
* Move constant folds for maths functions to new filersandifo2015-11-021-0/+1259
The new routines operate on the built-in enum rather than on tree decls. The idea is to extend this to handle internal functions too, with a combined enum for both. The patch also moves fold_fma too, with the same prototype. The long-term plan is to replace FMA_EXPR with an internal function, for consistency with the way that things like SQRT will be handled. Tested on x86_64-linux-gnu, arm-linux-gnueabi and aarch64-linux-gnu. gcc/ * builtins.h (fold_fma): Move to fold-const-call.h. * builtins.c: Include fold-const-call.h. (mathfn_built_in_2): New function, split out from... (mathfn_built_in_1): ...here. (do_real_to_int_conversion, fold_const_builtin_pow) (fold_const_builtin_logb, fold_const_builtin_significand) (fold_const_builtin_load_exponent, do_mpfr_arg1, do_mpfr_arg2) (do_mpfr_arg3, do_mpfr_sincos, do_mpfr_bessel_n, do_mpc_arg1): Delete. (fold_builtin_sincos): Use fold_const_call to handle constants. (fold_builtin_1, fold_builtin_2, fold_builtin_3): Add explicit checks for ERROR_MARK. Use fold_const_call to handle constant folds for math functions. (fold_fma): Move to fold-const-call.c. * fold-const.c: Include fold-const-call.h. * Makefile.in (OBJS): Add fold-const-call.o. (PLUGIN_HEADERS): Add fold-const-call.h. * realmpfr.h (real_from_mpfr): Allow the format to be specified directly. * realmpfr.c (real_from_mpfr): Likewise. * fold-const-call.h, fold-const-call.c: New files. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229669 138bc75d-0d04-0410-961f-82ee72b054a4