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

            Bug ID: 102224
           Summary: Incorrect compile on `x * copysign(1.0, x)`
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

float f(float x, float y)
{
    return x * copysignf(1.0f, x);
}

On latest trunk with -O3 on x86, this compiles to:

f(float):
  andps xmm0, XMMWORD PTR .LC0[rip]
  xorps xmm0, xmm0
  ret
.LC0:
  .long -2147483648
  .long 0
  .long 0
  .long 0

This is likely because the XOR_SIGN pattern emitted by
convert_expand_mult_copysign fails to check that x and y are not the same
(note: it can be optimized to ABS_EXPR in that case).

Reply via email to