diff options
author | Sujoy Saraswati <sujoy.saraswati@hpe.com> | 2015-12-22 14:04:30 +0000 |
---|---|---|
committer | Sujoy Saraswati <ssaraswati@gcc.gnu.org> | 2015-12-22 14:04:30 +0000 |
commit | 5a00b0aaf036edadc48861b91d3804796525c2d5 (patch) | |
tree | b911e1bd2a2f7a4a924f976f2156da6ea60dc25c /gcc/fold-const.c | |
parent | 9643ce888b6634d4f6c44ad3c48bd105f38474e8 (diff) | |
download | gcc-5a00b0aaf036edadc48861b91d3804796525c2d5.zip gcc-5a00b0aaf036edadc48861b91d3804796525c2d5.tar.gz gcc-5a00b0aaf036edadc48861b91d3804796525c2d5.tar.bz2 |
This series of patches fix PR61441.
This series of patches fix PR61441. This patch avoids various transformations
with signaling NaN operands when flag_signaling_nans is on, to avoid folding
which would lose exceptions.
Bootstrapped & regression-tested on x86_64-linux-gnu.
gcc/
* fold-const.c (const_binop): Convert sNaN to qNaN when
flag_signaling_nans is off.
(const_unop): Avoid the operation, other than NEGATE and
ABS, if flag_signaling_nans is on and the operand is an sNaN.
(fold_convert_const_real_from_real): Avoid the operation if
flag_signaling_nans is on and the operand is an sNaN.
(integer_valued_real_unary_p): Update comment stating it
returns false for sNaN values.
(integer_valued_real_binary_p, integer_valued_real_call_p): Same.
(integer_valued_real_single_p): Same.
(integer_valued_real_invalid_p, integer_valued_real_p): Same.
* fold-const-call.c (fold_const_pow): Avoid the operation
if flag_signaling_nans is on and the operand is an sNaN.
(fold_const_builtin_load_exponent) Same.
(fold_const_call_sss): Same for CASE_CFN_POWI.
* gimple-fold.c (gimple_assign_integer_valued_real_p): Same.
(gimple_call_integer_valued_real_p): Same.
(gimple_phi_integer_valued_real_p): Same.
(gimple_stmt_integer_valued_real_p): Same.
* simplify-rtx.c (simplify_const_unary_operation): Avoid the
operation if flag_signaling_nans is on and the operand is an sNaN.
(simplify_const_binary_operation): Same.
* tree-ssa-math-opts.c (gimple_expand_builtin_pow): Avoid the
operation if flag_signaling_nans is on and the operand is an sNaN.
* gcc.dg/pr61441.c: New testcase.
From-SVN: r231901
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index fff0285..5ad5112 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -1166,9 +1166,21 @@ const_binop (enum tree_code code, tree arg1, tree arg2) /* If either operand is a NaN, just return it. Otherwise, set up for floating-point trap; we return an overflow. */ if (REAL_VALUE_ISNAN (d1)) - return arg1; + { + /* Make resulting NaN value to be qNaN when flag_signaling_nans + is off. */ + d1.signalling = 0; + t = build_real (type, d1); + return t; + } else if (REAL_VALUE_ISNAN (d2)) - return arg2; + { + /* Make resulting NaN value to be qNaN when flag_signaling_nans + is off. */ + d2.signalling = 0; + t = build_real (type, d2); + return t; + } inexact = real_arithmetic (&value, code, &d1, &d2); real_convert (&result, mode, &value); @@ -1538,6 +1550,15 @@ const_binop (enum tree_code code, tree type, tree arg1, tree arg2) tree const_unop (enum tree_code code, tree type, tree arg0) { + /* Don't perform the operation, other than NEGATE and ABS, if + flag_signaling_nans is on and the operand is a signaling NaN. */ + if (TREE_CODE (arg0) == REAL_CST + && HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0))) + && REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (arg0)) + && code != NEGATE_EXPR + && code != ABS_EXPR) + return NULL_TREE; + switch (code) { CASE_CONVERT: @@ -1949,6 +1970,12 @@ fold_convert_const_real_from_real (tree type, const_tree arg1) REAL_VALUE_TYPE value; tree t; + /* Don't perform the operation if flag_signaling_nans is on + and the operand is a signaling NaN. */ + if (HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg1))) + && REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (arg1))) + return NULL_TREE; + real_convert (&value, TYPE_MODE (type), &TREE_REAL_CST (arg1)); t = build_real (type, value); @@ -13414,7 +13441,7 @@ tree_single_nonzero_warnv_p (tree t, bool *strict_overflow_p) /* Return true if the floating point result of (CODE OP0) has an integer value. We also allow +Inf, -Inf and NaN to be considered - integer values. + integer values. Return false for signaling NaN. DEPTH is the current nesting depth of the query. */ @@ -13447,7 +13474,7 @@ integer_valued_real_unary_p (tree_code code, tree op0, int depth) /* Return true if the floating point result of (CODE OP0 OP1) has an integer value. We also allow +Inf, -Inf and NaN to be considered - integer values. + integer values. Return false for signaling NaN. DEPTH is the current nesting depth of the query. */ @@ -13471,8 +13498,8 @@ integer_valued_real_binary_p (tree_code code, tree op0, tree op1, int depth) /* Return true if the floating point result of calling FNDECL with arguments ARG0 and ARG1 has an integer value. We also allow +Inf, -Inf and NaN to be - considered integer values. If FNDECL takes fewer than 2 arguments, - the remaining ARGn are null. + considered integer values. Return false for signaling NaN. If FNDECL + takes fewer than 2 arguments, the remaining ARGn are null. DEPTH is the current nesting depth of the query. */ @@ -13501,7 +13528,7 @@ integer_valued_real_call_p (combined_fn fn, tree arg0, tree arg1, int depth) /* Return true if the floating point expression T (a GIMPLE_SINGLE_RHS) has an integer value. We also allow +Inf, -Inf and NaN to be - considered integer values. + considered integer values. Return false for signaling NaN. DEPTH is the current nesting depth of the query. */ @@ -13535,7 +13562,7 @@ integer_valued_real_single_p (tree t, int depth) /* Return true if the floating point expression T (a GIMPLE_INVALID_RHS) has an integer value. We also allow +Inf, -Inf and NaN to be - considered integer values. + considered integer values. Return false for signaling NaN. DEPTH is the current nesting depth of the query. */ @@ -13563,6 +13590,7 @@ integer_valued_real_invalid_p (tree t, int depth) /* Return true if the floating point expression T has an integer value. We also allow +Inf, -Inf and NaN to be considered integer values. + Return false for signaling NaN. DEPTH is the current nesting depth of the query. */ |