From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 62ED53858D35; Tue, 8 Nov 2022 12:24:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 62ED53858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667910295; bh=0llYeEuX01g7lDxNzjNFrvMPjoZb0Rsxtl4mpx94LCM=; h=From:To:Subject:Date:From; b=qjMuRyxHS+5uS1XwX1QesBtiyw5nLZ0/XuO8wr73YqJykDShiEfFx0bUv25f+3ZSW GEmydPf4rYepdUClNDeAORBV0Lo9t2kbL+JFBOgdNrDuEVQvmjhPANCrs8bUWmrVTy LVlYn2OZuzn8hnPMrHA0jqWavZmI+BMxRd4+Yn/M= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3804] cdce: Fix up get_no_error_domain for new f{16, 32, 64, 128} builtins [PR107547] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: fa271afb58423014e2feef9f15c1a87428e64ddc X-Git-Newrev: 970dcd567449ec510477a043bbff70a0b960bd7f Message-Id: <20221108122455.62ED53858D35@sourceware.org> Date: Tue, 8 Nov 2022 12:24:55 +0000 (GMT) List-Id: https://gcc.gnu.org/g:970dcd567449ec510477a043bbff70a0b960bd7f commit r13-3804-g970dcd567449ec510477a043bbff70a0b960bd7f Author: Jakub Jelinek Date: Tue Nov 8 13:24:02 2022 +0100 cdce: Fix up get_no_error_domain for new f{16,32,64,128} builtins [PR107547] I've missed that this function needs to handle all the builtins that are handled in can_test_argument_range. The following patch does that. For many of the builtins (like acos, or log) it is the same range regardless of the floating point type, but for some (cosh, sinh, exp{,m1,2}) it is different for each format, so I had to compute those ranges. Note, seems the existing ranges were in some cases (e.g. for exp2) the smallest in absolute value which results infinite result, in others the largest which still results in finite result (but consistently so for the IEEE single vs. double). I've followed that for IEEE half and quad cases too, just am not sure why it was like that. I think get_domain with true, false is open interval rather than closed and the comments indicate that too, conservatively that is certainly correct. OT, with frange, perhaps we could DCE the calls unconditionally if frange can prove we are in the domain range. 2022-11-08 Jakub Jelinek PR tree-optimization/107547 * tree-call-cdce.cc (get_no_error_domain): Handle CASE_FLT_FN_FLOATN_NX of BUILT_IN_{ACOS,ASIN,ACOSH,ATANH,LOG,LOG2,LOG10,LOG1P}. Handle BUILT_IN_{COSH,SINH,EXP,EXPM1,EXP2}F{16,32,64,128}. * gcc.dg/pr107547.c: New test. Diff: --- gcc/testsuite/gcc.dg/pr107547.c | 40 +++++++++++++++++++++++++++++++++++ gcc/tree-call-cdce.cc | 46 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/gcc/testsuite/gcc.dg/pr107547.c b/gcc/testsuite/gcc.dg/pr107547.c new file mode 100644 index 00000000000..c6992c8674b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr107547.c @@ -0,0 +1,40 @@ +/* PR tree-optimization/107547 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int x; + +void +foo (void) +{ +#define TEST(...) \ + __builtin_acos##__VA_ARGS__ (x); \ + __builtin_asin##__VA_ARGS__ (x); \ + __builtin_acosh##__VA_ARGS__ (x); \ + __builtin_atanh##__VA_ARGS__ (x); \ + __builtin_cosh##__VA_ARGS__ (x); \ + __builtin_sinh##__VA_ARGS__ (x); \ + __builtin_log##__VA_ARGS__ (x); \ + __builtin_log2##__VA_ARGS__ (x); \ + __builtin_log10##__VA_ARGS__ (x); \ + __builtin_log1p##__VA_ARGS__ (x); \ + __builtin_exp##__VA_ARGS__ (x); \ + __builtin_expm1##__VA_ARGS__ (x); \ + __builtin_exp2##__VA_ARGS__ (x); \ + __builtin_sqrt##__VA_ARGS__ (x) + TEST (f); + TEST (); + TEST (l); +#ifdef __FLT16_MAX__ + TEST (f16); +#endif +#ifdef __FLT32_MAX__ + TEST (f32); +#endif +#ifdef __FLT64_MAX__ + TEST (f64); +#endif +#ifdef __FLT128_MAX__ + TEST (f128); +#endif +} diff --git a/gcc/tree-call-cdce.cc b/gcc/tree-call-cdce.cc index b4b14a016f7..1a74eefb8e4 100644 --- a/gcc/tree-call-cdce.cc +++ b/gcc/tree-call-cdce.cc @@ -693,20 +693,31 @@ get_no_error_domain (enum built_in_function fnc) { /* Trig functions: return [-1, +1] */ CASE_FLT_FN (BUILT_IN_ACOS): + CASE_FLT_FN_FLOATN_NX (BUILT_IN_ACOS): CASE_FLT_FN (BUILT_IN_ASIN): + CASE_FLT_FN_FLOATN_NX (BUILT_IN_ASIN): return get_domain (-1, true, true, 1, true, true); /* Hyperbolic functions. */ CASE_FLT_FN (BUILT_IN_ACOSH): + CASE_FLT_FN_FLOATN_NX (BUILT_IN_ACOSH): /* acosh: [1, +inf) */ return get_domain (1, true, true, 1, false, false); CASE_FLT_FN (BUILT_IN_ATANH): + CASE_FLT_FN_FLOATN_NX (BUILT_IN_ATANH): /* atanh: (-1, +1) */ return get_domain (-1, true, false, 1, true, false); + case BUILT_IN_COSHF16: + case BUILT_IN_SINHF16: + /* coshf16: (-11, +11) */ + return get_domain (-11, true, false, + 11, true, false); case BUILT_IN_COSHF: case BUILT_IN_SINHF: + case BUILT_IN_COSHF32: + case BUILT_IN_SINHF32: /* coshf: (-89, +89) */ return get_domain (-89, true, false, 89, true, false); @@ -714,21 +725,39 @@ get_no_error_domain (enum built_in_function fnc) case BUILT_IN_SINH: case BUILT_IN_COSHL: case BUILT_IN_SINHL: + case BUILT_IN_COSHF64: + case BUILT_IN_SINHF64: /* cosh: (-710, +710) */ return get_domain (-710, true, false, 710, true, false); + case BUILT_IN_COSHF128: + case BUILT_IN_SINHF128: + /* coshf128: (-11357, +11357) */ + return get_domain (-11357, true, false, + 11357, true, false); /* Log functions: (0, +inf) */ CASE_FLT_FN (BUILT_IN_LOG): + CASE_FLT_FN_FLOATN_NX (BUILT_IN_LOG): CASE_FLT_FN (BUILT_IN_LOG2): + CASE_FLT_FN_FLOATN_NX (BUILT_IN_LOG2): CASE_FLT_FN (BUILT_IN_LOG10): + CASE_FLT_FN_FLOATN_NX (BUILT_IN_LOG10): return get_domain (0, true, false, 0, false, false); CASE_FLT_FN (BUILT_IN_LOG1P): + CASE_FLT_FN_FLOATN_NX (BUILT_IN_LOG1P): return get_domain (-1, true, false, 0, false, false); /* Exp functions. */ + case BUILT_IN_EXPF16: + case BUILT_IN_EXPM1F16: + /* expf: (-inf, 11) */ + return get_domain (-1, false, false, + 11, true, false); case BUILT_IN_EXPF: case BUILT_IN_EXPM1F: + case BUILT_IN_EXPF32: + case BUILT_IN_EXPM1F32: /* expf: (-inf, 88) */ return get_domain (-1, false, false, 88, true, false); @@ -736,18 +765,35 @@ get_no_error_domain (enum built_in_function fnc) case BUILT_IN_EXPM1: case BUILT_IN_EXPL: case BUILT_IN_EXPM1L: + case BUILT_IN_EXPF64: + case BUILT_IN_EXPM1F64: /* exp: (-inf, 709) */ return get_domain (-1, false, false, 709, true, false); + case BUILT_IN_EXPF128: + case BUILT_IN_EXPM1F128: + /* expf128: (-inf, 11356) */ + return get_domain (-1, false, false, + 11356, true, false); + case BUILT_IN_EXP2F16: + /* exp2f16: (-inf, 16) */ + return get_domain (-1, false, false, + 16, true, false); case BUILT_IN_EXP2F: + case BUILT_IN_EXP2F32: /* exp2f: (-inf, 128) */ return get_domain (-1, false, false, 128, true, false); case BUILT_IN_EXP2: case BUILT_IN_EXP2L: + case BUILT_IN_EXP2F64: /* exp2: (-inf, 1024) */ return get_domain (-1, false, false, 1024, true, false); + case BUILT_IN_EXP2F128: + /* exp2f128: (-inf, 16384) */ + return get_domain (-1, false, false, + 16384, true, false); case BUILT_IN_EXP10F: case BUILT_IN_POW10F: /* exp10f: (-inf, 38) */