On Mon, Oct 5, 2026 at 2:59 PM Roger Sayle <[email protected]> wrote:
>
>
> This patch fixes PR tree-optimization/127544 by tightening the conditions
> under which gimple_expand_builtin_pow is allowed to convert pow(x,0.5)
> into sqrt(x).  Specifically, pow(-Inf,0.5) should return +Inf (by POSIX)
> but sqrt(-Inf) returns NaN, so this transformation is (also) unsafe in
> the presence of -Inf.  The patch also fixes an instance of using
> REAL_VALUE_ISSIGNALING_NAN when the intended behavior is to check
> tree_expr_maybe_signaling_nan_p.
>
> I'm also working on two follow-up patches... Obviously it should be
> possible to evaluate pow(-Inf,0.5) at compile-time (with -fno-math-errno)
> and in theory the new logic in this patch should enable us to optimize:
>     double foo(int x) { return __builtin_pow((double)x,0.5); }
> into sqrt, as conversion of an integer to double can't produce either
> an infinity or a negative zero, but unfortunately the tree_expr_maybe_*
> predicates aren't quite clever enough yet.
>
>
> This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
> and make -k check, both with and without --target_board=unix{-m32}
> with no new failures.  Ok for mainline?

OK.

Thanks,
Richard.

>
> 2026-10-05  Roger Sayle  <[email protected]>
>
> gcc/ChangeLog
>         PR tree-optimization/127544
>         PR tree-optimization/126562
>         * tree-ssa-math-opts.cc (gimple_expand_builtin_pow): Use
>         tree_expr_maybe_signaling_nan_p insted of REAL_VALUE_ISSIGNALING_NAN
>         to check whether an operand may be a signaling NaN.  pow(x,0.5)
>         also can't be transformed to sqrt(x) if x may be -Inf.
>
> gcc/testsuite/ChangeLog
>         PR tree-optimization/127544
>         PR tree-optimization/126562
>         * gcc.dg/pr127544-1.c: New test case.
>
>
> Thanks in advance,
> Roger
> --
>

Reply via email to