public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-7072] match.pd: Fix x * 0.0 -> 0.0 folding [PR104389] Date: Sat, 5 Feb 2022 09:54:15 +0000 (GMT) [thread overview] Message-ID: <20220205095415.EEEFE3858D28@sourceware.org> (raw) https://gcc.gnu.org/g:b3763384a1f696260f3ee7bda8c0e7e4ad732ad9 commit r12-7072-gb3763384a1f696260f3ee7bda8c0e7e4ad732ad9 Author: Jakub Jelinek <jakub@redhat.com> Date: Sat Feb 5 10:52:19 2022 +0100 match.pd: Fix x * 0.0 -> 0.0 folding [PR104389] The recent PR95115 change to punt in const_binop on folding operation with non-NaN operands into NaN if flag_trapping_math broke the following testcase, because the x * 0.0 simplification punts just if x maybe a NaN (because NaN * 0.0 is NaN not 0.0) or if one of the operands could be negative zero. But Inf * 0.0 or -Inf * 0.0 is also NaN, not 0.0, so when NaNs are honored we need to punt for possible infinities too. 2022-02-05 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/104389 * match.pd (x * 0 -> 0): Punt if x maybe infinite and NaNs are honored. * gcc.dg/pr104389.c: New test. Diff: --- gcc/match.pd | 4 +++- gcc/testsuite/gcc.dg/pr104389.c | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/gcc/match.pd b/gcc/match.pd index 10ff867e854..7bbb80172fc 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -256,10 +256,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* Maybe fold x * 0 to 0. The expressions aren't the same when x is NaN, since x * 0 is also NaN. Nor are they the same in modes with signed zeros, since multiplying a - negative value by 0 gives -0, not +0. */ + negative value by 0 gives -0, not +0. Nor when x is +-Inf, + since x * 0 is NaN. */ (simplify (mult @0 real_zerop@1) (if (!tree_expr_maybe_nan_p (@0) + && (!HONOR_NANS (type) || !tree_expr_maybe_infinite_p (@0)) && !tree_expr_maybe_real_minus_zero_p (@0) && !tree_expr_maybe_real_minus_zero_p (@1)) @1)) diff --git a/gcc/testsuite/gcc.dg/pr104389.c b/gcc/testsuite/gcc.dg/pr104389.c new file mode 100644 index 00000000000..0c6c85a4f48 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr104389.c @@ -0,0 +1,26 @@ +/* PR tree-optimization/104389 */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ +/* { dg-add-options ieee } */ +/* { dg-require-effective-target inf } */ + +__attribute__((noipa)) double +foo (void) +{ + double a = __builtin_huge_val (); + return a * 0.0; +} + +__attribute__((noipa)) long double +bar (void) +{ + return __builtin_huge_vall () * 0.0L; +} + +int +main () +{ + if (!__builtin_isnan (foo ()) || !__builtin_isnanl (bar ())) + __builtin_abort (); + return 0; +}
reply other threads:[~2022-02-05 9:54 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220205095415.EEEFE3858D28@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).