public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix simplify_const_unary_operation sNaN handling (PR tree-optimization/61441)
@ 2017-02-20 23:49 Jakub Jelinek
  2017-02-21  1:57 ` Segher Boessenkool
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2017-02-20 23:49 UTC (permalink / raw)
  To: Richard Biener, Segher Boessenkool, Eric Botcazou,
	Joseph S. Myers, Saraswati, Sujoy (OSTL)
  Cc: gcc-patches

Hi!

As I wrote earlier today on gcc-patches, pr61441.c started failing
on i?86-linux when -fsignaling-nans argument has been added to it.

I believe this is because the simplify_const_unary_operation
changes in r231901 were broken, when the operand is a sNaN and
-fsignaling-nans, we want to avoid folding FLOAT_TRUNCATE, FLOAT_EXTEND
and FIX of a sNaN, not just return it unmodified (this is in a switch
that optionally modifies the real value just to create another CONST_DOUBLE
usually in a different mode out from it.  This patch instead
returns NULL, which means no simplification.

Bootstrapped/regtested on x86_64-linux and i686-linux, fixes pr61441.c
on the latter, ok for trunk?

2017-02-20  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/61441
	* simplify-rtx.c (simplify_const_unary_operation): For
	-fsignaling-nans and sNaN operand, return NULL_RTX rather than
	the sNaN unmodified.

--- gcc/simplify-rtx.c.jj	2017-01-01 12:45:37.000000000 +0100
+++ gcc/simplify-rtx.c	2017-02-20 20:02:33.446251366 +0100
@@ -1889,23 +1889,26 @@ simplify_const_unary_operation (enum rtx
 	case FLOAT_TRUNCATE:
 	  /* Don't perform the operation if flag_signaling_nans is on
 	     and the operand is a signaling NaN.  */
-	  if (!(HONOR_SNANS (mode) && REAL_VALUE_ISSIGNALING_NAN (d)))
-	    d = real_value_truncate (mode, d);
+	  if (HONOR_SNANS (mode) && REAL_VALUE_ISSIGNALING_NAN (d))
+	    return NULL_RTX;
+	  d = real_value_truncate (mode, d);
 	  break;
 	case FLOAT_EXTEND:
-	  /* All this does is change the mode, unless changing
-	     mode class.  */
 	  /* Don't perform the operation if flag_signaling_nans is on
 	     and the operand is a signaling NaN.  */
-	  if (GET_MODE_CLASS (mode) != GET_MODE_CLASS (GET_MODE (op))
-	      && !(HONOR_SNANS (mode) && REAL_VALUE_ISSIGNALING_NAN (d)))
+	  if (HONOR_SNANS (mode) && REAL_VALUE_ISSIGNALING_NAN (d))
+	    return NULL_RTX;
+	  /* All this does is change the mode, unless changing
+	     mode class.  */
+	  if (GET_MODE_CLASS (mode) != GET_MODE_CLASS (GET_MODE (op)))
 	    real_convert (&d, mode, &d);
 	  break;
 	case FIX:
 	  /* Don't perform the operation if flag_signaling_nans is on
 	     and the operand is a signaling NaN.  */
-	  if (!(HONOR_SNANS (mode) && REAL_VALUE_ISSIGNALING_NAN (d)))
-	    real_arithmetic (&d, FIX_TRUNC_EXPR, &d, NULL);
+	  if (HONOR_SNANS (mode) && REAL_VALUE_ISSIGNALING_NAN (d))
+	    return NULL_RTX;
+	  real_arithmetic (&d, FIX_TRUNC_EXPR, &d, NULL);
 	  break;
 	case NOT:
 	  {

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix simplify_const_unary_operation sNaN handling (PR tree-optimization/61441)
  2017-02-20 23:49 [PATCH] Fix simplify_const_unary_operation sNaN handling (PR tree-optimization/61441) Jakub Jelinek
@ 2017-02-21  1:57 ` Segher Boessenkool
  0 siblings, 0 replies; 2+ messages in thread
From: Segher Boessenkool @ 2017-02-21  1:57 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Richard Biener, Eric Botcazou, Joseph S. Myers, Saraswati,
	Sujoy (OSTL),
	gcc-patches

On Tue, Feb 21, 2017 at 12:12:28AM +0100, Jakub Jelinek wrote:
> As I wrote earlier today on gcc-patches, pr61441.c started failing
> on i?86-linux when -fsignaling-nans argument has been added to it.
> 
> I believe this is because the simplify_const_unary_operation
> changes in r231901 were broken, when the operand is a sNaN and
> -fsignaling-nans, we want to avoid folding FLOAT_TRUNCATE, FLOAT_EXTEND
> and FIX of a sNaN, not just return it unmodified (this is in a switch
> that optionally modifies the real value just to create another CONST_DOUBLE
> usually in a different mode out from it.  This patch instead
> returns NULL, which means no simplification.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, fixes pr61441.c
> on the latter, ok for trunk?

This patch looks fine to me, fwiw.

I did test the patch adding -fsignaling-nans to those to testcases on x86,
but for some reason there is no issignaling on the machine I tested on,
so the testcases are skipped.

Thanks,


Segher

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-02-21  0:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-20 23:49 [PATCH] Fix simplify_const_unary_operation sNaN handling (PR tree-optimization/61441) Jakub Jelinek
2017-02-21  1:57 ` Segher Boessenkool

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).