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

            Bug ID: 127983
           Summary: wrong code at -O1 and above with -mavx2 for vector
                    broadcasts of a scalar before and after its increment
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kyuwoncho18 at gmail dot com
  Target Milestone: ---
            Target: x86_64-pc-linux-gnu

typedef int v4si __attribute__((vector_size(16)));
typedef int v8si __attribute__((vector_size(32)));
volatile v4si x;
volatile v8si y;
int main(void) {
  volatile int z = 1;
  int s = z;
  for (int i = 0; i < z; i++) {
    x = (v4si){s, s, s, s};
    s++;
    y = (v8si){s, s, s, s, s, s, s, s};
  }
  return y[0];
}

godbolt: https://godbolt.org/z/n7TbTf9Wx

With -O0 -mavx2, it returns 2, but with -O1, -O2, -O3 or -Os -mavx2, it returns
1: y gets the value of s before the increment. -fdisable-rtl-cse1
-fdisable-rtl-cse2 avoids it.

Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.

Reply via email to