diff mbox

Fix simplify_const_unary_operation sNaN handling (PR tree-optimization/61441)

Message ID 20170220231228.GJ1849@tucnak
State New
Headers show

Commit Message

Jakub Jelinek Feb. 20, 2017, 11:12 p.m. UTC
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.


	Jakub

Comments

Segher Boessenkool Feb. 21, 2017, 12:48 a.m. UTC | #1
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
diff mbox

Patch

--- 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:
 	  {