https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128798

            Bug ID: 128798
           Summary: [16/17 Regression] ICE: forwprop folds cargf into
                    atan2f without an SSA update
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: [email protected]
  Target Milestone: ---

The following test case causes an ICE at -O1 and above:

float atan2f (float, float);

float r, x, y, z;

void
f (void)
{
  r = __builtin_cargf (z);
}

void
g (void)
{
  __builtin_atan2f (y, x);
}

$ sparc-rtems7-gcc -O2 -c pr.c
during GIMPLE pass: forwprop
pr.c: In function 'f':
pr.c:15:1: internal compiler error: in execute_todo, at passes.cc:2152

The compilers were GCC 17.0.0 20261117 (master 9571dd0b7219) and
GCC 16.2.1 20261117 (releases/gcc-16 75eb66ac4c08). The GCC 16 branch reports
"in execute_function_todo, at passes.cc:2072", which is the assertion
!need_ssa_update_p (fn).

forwprop1 folds __builtin_cargf (COMPLEX_EXPR <z, 0.0>) of f into
__builtin_atan2f (0.0, z). The call of cargf has no virtual operands. With
-fmath-errno, the call of atan2f may set errno and needs a virtual definition,
so the function needs an SSA update. forwprop does not request it.

The ICE needs all of the following:

- the explicit declaration of atan2f,
- the call of __builtin_atan2f in g after f,
- -fmath-errno, the default.

With -fno-math-errno, without the declaration, without g, or with g before f,
the test case compiles.

GCC 16.1.1 shows the ICE also for the arm, aarch64, riscv, x86_64, i386, m68k,
microblaze and or1k targets with -rtems7. x86_64-linux-gnu and powerpc-rtems7
do not show it with the same source.

GCC 15.3.1 20261015 (releases/gcc-15 0b2cdf07de08) compiles the test case for
sparc-rtems7.

The test case comes from a reduction of libgomp.c++/target-std__complex.C,
which fails in the same way in std::__complex_arg (__complex__ float).

Reply via email to