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

            Bug ID: 88892
           Summary: Double-to-float conversion uses wrong rounding mode
                    when followed by memcpy
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fw at gcc dot gnu.org
  Target Milestone: ---
            Target: powerpc64le-redhat-linux-gnu

With gcc-8.2.1-6.fc28.ppc64le, this code

void
f (double d, char *target)
{
  float f = d;
  __builtin_memcpy (target, &f, sizeof (f));
}

results (with -O2) in (omitting the unwinding information):

f:
        stfs 1,0(4)
        blr

This is incorrect because stfs rounds to zero.  An frsp instruction is missing
before the stfs (and would be emitted without the memcpy).

(GCC documents that the default rounding mode “is round-to-zero for all
floating point to integer conversions, and round-to-nearest for all other
arithmetic truncations”; see -frounding-mode.)

Found by the Python testsuite: https://bugs.python.org/issue35752

Reply via email to