From f7657db990578e6193922cc0a4f8969c1bef368a Mon Sep 17 00:00:00 2001 From: "Kaveh R. Ghazi" Date: Tue, 9 Sep 2003 22:10:32 +0000 Subject: builtins.c (real_dconstp, [...]): New, split out from fold_builtin. * builtins.c (real_dconstp, fold_builtin_logarithm, fold_builtin_exponent): New, split out from fold_builtin. Also generalize to add log2, log10, exp2 and exp10/pow10 equivalents. * emit-rtl.c (dconst3, dconst10, dconstthird): New. (init_emit_once): Initialize new dconsts, use ARRAY_SIZE in lieu of hardcoded array size. * fold-const.c (fold): Add cases for exp2, exp10 and pow10. (tree_expr_nonnegative_p): Likewise. * real.h (dconst3, dconst10, dconstthird): New. testsuite: * gcc.dg/torture/builtin-explog-1.c: New testcase. From-SVN: r71252 --- gcc/fold-const.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'gcc/fold-const.c') diff --git a/gcc/fold-const.c b/gcc/fold-const.c index d5b98fe..c9a43e6 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6110,10 +6110,20 @@ fold (tree expr) return build_function_call_expr (sqrtfn, arglist); } - /* Optimize exp(x)*exp(y) as exp(x+y). */ - if ((fcode0 == BUILT_IN_EXP && fcode1 == BUILT_IN_EXP) - || (fcode0 == BUILT_IN_EXPF && fcode1 == BUILT_IN_EXPF) - || (fcode0 == BUILT_IN_EXPL && fcode1 == BUILT_IN_EXPL)) + /* Optimize expN(x)*expN(y) as expN(x+y). */ + if (fcode0 == fcode1 + && (fcode0 == BUILT_IN_EXP + || fcode0 == BUILT_IN_EXPF + || fcode0 == BUILT_IN_EXPL + || fcode0 == BUILT_IN_EXP2 + || fcode0 == BUILT_IN_EXP2F + || fcode0 == BUILT_IN_EXP2L + || fcode0 == BUILT_IN_EXP10 + || fcode0 == BUILT_IN_EXP10F + || fcode0 == BUILT_IN_EXP10L + || fcode0 == BUILT_IN_POW10 + || fcode0 == BUILT_IN_POW10F + || fcode0 == BUILT_IN_POW10L)) { tree expfn = TREE_OPERAND (TREE_OPERAND (arg0, 0), 0); tree arg = build (PLUS_EXPR, type, @@ -6445,10 +6455,19 @@ fold (tree expr) if (flag_unsafe_math_optimizations) { enum built_in_function fcode = builtin_mathfn_code (arg1); - /* Optimize x/exp(y) into x*exp(-y). */ + /* Optimize x/expN(y) into x*expN(-y). */ if (fcode == BUILT_IN_EXP || fcode == BUILT_IN_EXPF - || fcode == BUILT_IN_EXPL) + || fcode == BUILT_IN_EXPL + || fcode == BUILT_IN_EXP2 + || fcode == BUILT_IN_EXP2F + || fcode == BUILT_IN_EXP2L + || fcode == BUILT_IN_EXP10 + || fcode == BUILT_IN_EXP10F + || fcode == BUILT_IN_EXP10L + || fcode == BUILT_IN_POW10 + || fcode == BUILT_IN_POW10F + || fcode == BUILT_IN_POW10L) { tree expfn = TREE_OPERAND (TREE_OPERAND (arg1, 0), 0); tree arg = build1 (NEGATE_EXPR, type, @@ -8674,6 +8693,15 @@ tree_expr_nonnegative_p (tree t) case BUILT_IN_EXP: case BUILT_IN_EXPF: case BUILT_IN_EXPL: + case BUILT_IN_EXP2: + case BUILT_IN_EXP2F: + case BUILT_IN_EXP2L: + case BUILT_IN_EXP10: + case BUILT_IN_EXP10F: + case BUILT_IN_EXP10L: + case BUILT_IN_POW10: + case BUILT_IN_POW10F: + case BUILT_IN_POW10L: case BUILT_IN_FABS: case BUILT_IN_FABSF: case BUILT_IN_FABSL: -- cgit v1.1