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

            Bug ID: 110755
           Summary: Wrong optimization of fabs on ppc64el at -O1
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aurelien at aurel32 dot net
  Target Milestone: ---

The following code, extracted and simplified from the PowerPC implementation of
nearbyintf() in the GNU libc is wrongly optimized at -O1 and -O2 on ppc64el
with GCC 13. The fabs is removed, while it is not the case with GCC 12

#include <fenv.h>
#include <math.h>
#include <stdio.h>

static float my_nearbyintf (float x)
{ 
  float r = x;

  if (x > 0.0)
    { 
      r += 0x1p+23;
      r -= 0x1p+23;
      r = fabs (r);
    }

  return r;
}

int main()
{
        volatile float in = 0.5f;

        fesetround (FE_DOWNWARD);
        printf("mynearbyintf(in) = %lf\n", my_nearbyintf(in));
}

This causes the result to have the wrong sign.

Reply via email to