public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Sujoy Saraswati <ssaraswati@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: Fix 61441
Date: Tue, 01 Sep 2015 12:21:00 -0000	[thread overview]
Message-ID: <CAFiYyc0rwpQ_v1x4WzbrzaPfiFQetfq_hLur44otKwceqo6CDg@mail.gmail.com> (raw)
In-Reply-To: <CA+ZXfhXZWO8eOCYGPv3nomrfK7zzWHkXSJE++jw0heHxbQoqaA@mail.gmail.com>

On Tue, Sep 1, 2015 at 12:23 PM, Sujoy Saraswati <ssaraswati@gmail.com> wrote:
> The following patch fixes 61441. It converts sNaN to qNaN on folding
> when -fno-signaling-nans is used.
>
> Bootstrap and regression tests on x86_64-linux-gnu and
> aarch64-unknown-linux-gnu passed with changes done on trunk.
>
> Is this fix fine ?

Note that I'm curious what
the actual bug is - is it that (double) sNaN creates a sNaN?  Then the fix
should be elsewhere, in constant folding itself
(fold_convert_const_real_from_real
or real_convert).

If that isn't the bug you have very many other passes to fix for the
same problem.

So - can you please explain?

Thanks,
Richard.

> Regards,
> Sujoy
>
> 2015-09-01  Sujoy Saraswati <ssaraswati@gmail.com>
>
>         PR tree-optimization/61441
>         * tree-ssa-ccp.c (convert_snan_to_qnan): Convert sNaN to qNaN when
>         flag_signaling_nans is off.
>         (ccp_fold_stmt, visit_assignment, visit_cond_stmt): call
>         convert_snan_to_qnan to convert sNaN to qNaN on constant folding.
>
>         PR tree-optimization/61441
>         * gcc.dg/pr61441.c: New testcase.
>
> Index: gcc/tree-ssa-ccp.c
> ===================================================================
> --- gcc/tree-ssa-ccp.c  (revision 226965)
> +++ gcc/tree-ssa-ccp.c  (working copy)
> @@ -560,6 +560,24 @@ value_to_wide_int (ccp_prop_value_t val)
>    return 0;
>  }
>
> +/* Convert sNaN to qNaN when flag_signaling_nans is off */
> +
> +static void
> +convert_snan_to_qnan (tree expr)
> +{
> +  if (expr
> +      && (TREE_CODE (expr) == REAL_CST)
> +      && !flag_signaling_nans)
> +  {
> +    REAL_VALUE_TYPE *d = TREE_REAL_CST_PTR (expr);
> +
> +    if (HONOR_NANS (TYPE_MODE (TREE_TYPE (expr)))
> +        && REAL_VALUE_ISNAN (*d)
> +        && d->signalling)
> +      d->signalling = 0;
> +  }
> +}
> +
>  /* Return the value for the address expression EXPR based on alignment
>     information.  */
>
> @@ -2156,6 +2174,7 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi)
>         if (val.lattice_val != CONSTANT
>             || val.mask != 0)
>           return false;
> +        convert_snan_to_qnan (val.value);
>
>         if (dump_file)
>           {
> @@ -2197,7 +2216,10 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi)
>             bool res;
>             if (!useless_type_conversion_p (TREE_TYPE (lhs),
>                                             TREE_TYPE (new_rhs)))
> +            {
>               new_rhs = fold_convert (TREE_TYPE (lhs), new_rhs);
> +              convert_snan_to_qnan (new_rhs);
> +            }
>             res = update_call_from_tree (gsi, new_rhs);
>             gcc_assert (res);
>             return true;
> @@ -2216,6 +2238,7 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi)
>              tree new_rhs = fold_builtin_alloca_with_align (stmt);
>              if (new_rhs)
>               {
> +                convert_snan_to_qnan (new_rhs);
>                 bool res = update_call_from_tree (gsi, new_rhs);
>                 tree var = TREE_OPERAND (TREE_OPERAND (new_rhs, 0),0);
>                 gcc_assert (res);
> @@ -2260,7 +2283,10 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi)
>           {
>             tree rhs = unshare_expr (val);
>             if (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (rhs)))
> +            {
>               rhs = fold_build1 (VIEW_CONVERT_EXPR, TREE_TYPE (lhs), rhs);
> +              convert_snan_to_qnan (rhs);
> +            }
>             gimple_assign_set_rhs_from_tree (gsi, rhs);
>             return true;
>           }
> @@ -2292,6 +2318,7 @@ visit_assignment (gimple stmt, tree *output_p)
>        /* Evaluate the statement, which could be
>          either a GIMPLE_ASSIGN or a GIMPLE_CALL.  */
>        val = evaluate_stmt (stmt);
> +      convert_snan_to_qnan (val.value);
>
>        /* If STMT is an assignment to an SSA_NAME, we only have one
>          value to set.  */
> @@ -2324,6 +2351,7 @@ visit_cond_stmt (gimple stmt, edge *taken_edge_p)
>    if (val.lattice_val != CONSTANT
>        || val.mask != 0)
>      return SSA_PROP_VARYING;
> +  convert_snan_to_qnan (val.value);
>
>    /* Find which edge out of the conditional block will be taken and add it
>       to the worklist.  If no single edge can be determined statically,
>
> Index: gcc/testsuite/gcc.dg/pr61441.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/pr61441.c      (revision 0)
> +++ gcc/testsuite/gcc.dg/pr61441.c      (working copy)
> @@ -0,0 +1,17 @@
> +/* { dg-do run } */
> +/* { dg-options "-O1 -lm" } */
> +
> +#define _GNU_SOURCE
> +#include <stdio.h>
> +#include <math.h>
> +
> +int main (void)
> +{
> +  float sNaN = __builtin_nansf ("");
> +  double x = (double) sNaN;
> +  if (issignaling(x))
> +  {
> +    __builtin_abort();
> +  }
> +  return 0;
> +}

  reply	other threads:[~2015-09-01 12:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-01 10:23 Sujoy Saraswati
2015-09-01 12:21 ` Richard Biener [this message]
2015-09-02 11:36   ` Sujoy Saraswati
2015-09-02 11:56     ` Richard Biener
2015-09-02 12:16       ` Sujoy Saraswati
2015-09-10  7:33       ` Sujoy Saraswati
2015-09-14 13:50         ` Richard Biener
2015-09-14 20:39           ` Joseph Myers
2015-09-16 13:01             ` Sujoy Saraswati
2015-09-16 17:03               ` Joseph Myers
2015-10-13 10:46                 ` Sujoy Saraswati
2015-10-28 17:19                   ` Joseph Myers
2015-11-05 11:29                     ` Sujoy Saraswati
2015-11-05 16:58                       ` Joseph Myers
2015-11-06  4:56                         ` Sujoy Saraswati
2015-11-06 13:09                           ` Joseph Myers
2015-11-26  8:28                             ` Saraswati, Sujoy (OSTL)

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=CAFiYyc0rwpQ_v1x4WzbrzaPfiFQetfq_hLur44otKwceqo6CDg@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ssaraswati@gmail.com \
    /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: link
Be 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).