[Bug c++/82409] New: Superflous pxor instructions in the generated assembly.

maxim.yegorushkin at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Oct 2 18:00:00 GMT 2017


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

            Bug ID: 82409
           Summary: Superflous pxor instructions in the generated
                    assembly.
           Product: gcc
           Version: 7.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: maxim.yegorushkin at gmail dot com
  Target Milestone: ---

For the following function:

    double f(int a, int b) {
       return static_cast<double>(a - b) / (a + b);
    }

g++-7.2 with flags "-O3 -std=c++14" generates the following code:

    f(int, int):
        pxor    %xmm0, %xmm0
        movl    %edi, %eax
        pxor    %xmm1, %xmm1
        subl    %esi, %eax
        addl    %esi, %edi
        cvtsi2sd        %eax, %xmm0
        cvtsi2sd        %edi, %xmm1
        divsd   %xmm1, %xmm0
        ret

Note pxor instructions in there to zero out the unused upper bits of xmm
registers. Are they necessary?

clang++-3.5 and newer generates similar code but without these pxor
instructions.


More information about the Gcc-bugs mailing list