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

            Bug ID: 94031
           Summary: missing floating-point optimization of x + 0 when x is
                    not zero
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincent-gcc at vinc17 dot net
  Target Milestone: ---

In floating point, when x is not 0 (and not sNaN when supported), x + 0 can be
optimized to x. GCC misses this optimization:

void bar (double);

void foo1 (double x)
{
  x *= 2.0;  /* cannot be sNaN */
  if (x != 0)
    bar (x - 0);
}

void foo2 (double x)
{
  x *= 2.0;  /* cannot be sNaN */
  if (x != 0)
    bar (x + 0);
}

In foo1, x - 0 can be optimized to x in rounding to nearest (even when x is
±0), and GCC optimizes as expected:

.L4:
        jmp     bar@PLT

In foo2, in order to be able to optimize, one needs x != 0, guaranteed by the
"if" condition, but GCC misses the optimization:

.L10:
        addsd   %xmm1, %xmm0
        jmp     bar@PLT

Tested under Debian x86_64 with gcc-10 (Debian 10-20200222-1) 10.0.1 20200222
(experimental) [master revision
01af7e0a0c2:487fe13f218:e99b18cf7101f205bfdd9f0f29ed51caaec52779]

Reply via email to