[Bug rtl-optimization/82153] New: missed optimization: double rounding

arjan at linux dot intel.com gcc-bugzilla@gcc.gnu.org
Fri Sep 8 20:48:00 GMT 2017


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

            Bug ID: 82153
           Summary: missed optimization: double rounding
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arjan at linux dot intel.com
  Target Milestone: ---

#include <math.h>

int roundme(double A)
{
        return floor(A * 4.3);
}

leads to

0000000000000000 <roundme>:
   0:   f2 0f 59 05 00 00 00    mulsd  0x0(%rip),%xmm0        # 8 <roundme+0x8>
   7:   00
   8:   66 0f 3a 0b c0 09       roundsd $0x9,%xmm0,%xmm0
   e:   f2 0f 2c c0             cvttsd2si %xmm0,%eax
  12:   c3                      retq

both roundsd $0x9 and cvttsd2si truncate (floor) their argument, so gcc is
doing redundant work here; roundsd is +/- 8 cycles which is not cheap.


More information about the Gcc-bugs mailing list