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

            Bug ID: 94852
           Summary: -ffloat-store on x64 target
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vanyacpp at gmail dot com
  Target Milestone: ---

At the moment -ffloat-store significantly pessimizes the code generation
regardless of whether -mfpmath=sse -msse2 are used or not:

float f(float a, float b)
{
    return a + b;
}

-O2:
        addss   xmm0, xmm1
        ret

-O2 -ffloat-store:
        movss   DWORD PTR [rsp-20], xmm0
        movss   xmm0, DWORD PTR [rsp-20]
        movss   DWORD PTR [rsp-24], xmm1
        addss   xmm0, DWORD PTR [rsp-24]
        movss   DWORD PTR [rsp-4], xmm0
        movss   xmm0, DWORD PTR [rsp-4]
        ret

Note that -mfpmath=sse -msse2 are the defaults on x86-64. My understanding is
that -ffloat-store doesn't affect the result of floating point operations when
SSE math is used. If this is true -ffloat-store pessimizes generated code
without any change in observable behavior.

Recently I have found a steam game that targets x86-64 and was compiled with
-ffloat-store (presumably by mistake). For details see:
https://forums.factorio.com/viewtopic.php?f=30&t=81134 . When -ffloat-store was
removed a developer reported a 35% speedup of the Linux version of the game.

My guess is -ffloat-store might be used by mistake when someone tries to get
reproducible results on x86 without realizing that the same flags affects the
performance negatively on x86-64.

To prevent issues like this in the future I think GCC could do two things:
1. Ignore -ffloat-store when it doesn't affect the result of floating-point
operations pretending that redundant loads/stores are optimized.
2. Issue a warning when -ffloat-store doesn't affect the result of
floating-point operations. Because there is no point in using a flag which only
effect is pessimizing code generation.

Reply via email to