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

            Bug ID: 88598
           Summary: simplification of multiplication by 1 or 0 fails
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincenzo.innocente at cern dot ch
  Target Milestone: ---

g++ fails to optimize the code below
even with -Ofast https://godbolt.org/z/mYRgVX
independently of vectorization options https://godbolt.org/z/XMnCNz
clang optimizes (return zero for "foo" and v[1] for "bar") even for just
-ffinite-math-only -fno-signed-zeros -O2
  https://godbolt.org/z/KU5f-x

float foo(float const * __restrict__ v) {
  float j[5] = {0.,0.,0.,0.,0.};
  float ret=0.;
  for (int i=0; i<5; ++i) ret +=j[i]*v[i];
  return ret;
}


float bar(float const * __restrict__ v) {
  float j[5] = {0.,1.,0.,0.,0.};
  float ret=0.;
  for (int i=0; i<5; ++i) ret +=j[i]*v[i];
  return ret;
}

Reply via email to