On Thu, Oct 28, 2021 at 01:32:17PM +0200, Richard Biener wrote:
> diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
> index f38b6d7d31c..a16395befcd 100644
> --- a/gcc/simplify-rtx.c
> +++ b/gcc/simplify-rtx.c
> @@ -1917,6 +1917,19 @@ simplify_const_unary_operation (enum rtx_code code,
> machine_mode mode,
> return 0;
>
> d = real_value_truncate (mode, d);
> +
> + /* Avoid the folding if flag_rounding_math is on and the
> + conversion is not exact. */
> + if (HONOR_SIGN_DEPENDENT_ROUNDING (mode))
> + {
> + bool fail = false;
> + wide_int w = real_to_integer (&d, &fail,
> + GET_MODE_PRECISION
> + (as_a <scalar_int_mode> (op_mode)));
> + if (fail || wi::ne_p (w, wide_int (rtx_mode_t (op, op_mode))))
> + return 0;
> + }
> +
> return const_double_from_real_value (d, mode);
> }
> else if (code == UNSIGNED_FLOAT && CONST_SCALAR_INT_P (op))
What about the else if case (i.e. UNSIGNED_FLOAT)?
And I think it would be nice to test the simplify-rtx.c code somewhere,
perhaps gcc/testsuite/gcc.dg/rtl/x86_64 testcase and check that we
simplify with -frounding-math e.g. UNSIGNED_FLOAT from DImode
0x8000000000000000 or FLOAT or UNSIGNED_FLOAT from DImode
0x7ffffffffffffc00, but will not fold FLOAT or UNSIGNED_FLOAT from
DImode 0x7ffffffffffffc01 or 0x7fffffffffffffff.
Jakub