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

            Bug ID: 117126
           Summary: GCC 14 generates redundant movq xmm1, xmm1
                    instructions with -O2 optimization, leading to code
                    bloat (regression from GCC 13.x)
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: peter.fors at mindkiller dot com
  Target Milestone: ---

This is a regression from GCC 13.x to GCC 14. The generated code contains
redundant movq xmm1, xmm1 and movq xmm0, xmm0 instructions when using -O2
optimization. The issue occurs in all GCC 14 releases, including the current
trunk.

Steps to Reproduce: Compile the following code using gcc -O2:

Example code:
#include <stdint.h>

float velocityX = 0;
float velocityY = 0;
const float maxSpeed = 3.0;
const float rampSpeed = 4.0;

float velocity[2] = {0.0f, 0.0f} ;
float position[2] = {0.0f, 0.0f};

void update(float analog[2], float deltaTime) {
   float targetVelocity[2] = {analog[0] * maxSpeed, analog[1] * maxSpeed};

   velocity[0] += (targetVelocity[0] - velocity[0]) * rampSpeed * deltaTime;
   velocity[1] += (targetVelocity[1] - velocity[1]) * rampSpeed * deltaTime;
   position[0] += velocity[0] * deltaTime;
   position[1] += velocity[1] * deltaTime;
}

Godbolt Example: https://godbolt.org/z/j5xKxbasf  (same code as above with
gcc14.1 and 13.3 assembly output set up with -O2).

Expected Behavior: The code should not contain redundant movq xmm1, xmm1 and
movq xmm0, xmm0 instructions.

Actual Behavior: GCC 14 generates redundant move-to-self instructions (movq
xmm1, xmm1 and movq xmm0, xmm0) around functional instructions.

Regression Window:

    Last tested GCC 13.1 13.2 13.3 (no issue)
    First release of GCC 14 shows the issue
    Issue persists in all GCC 14 versions including trunk

Additional Info: Using -march=native reduces the number of redundant
instructions, but they are still present.
  • [Bug c/117126] New: GCC 14 g... peter.fors at mindkiller dot com via Gcc-bugs

Reply via email to