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

            Bug ID: 82750
           Summary: Incorrect code for mednafen's array copy test with -O3
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cand at gmx dot com
  Target Milestone: ---

Mednafen's TestGCC81740 test fails with gcc 7.2 using -O3, but it works with
-O2 and -O3 -fno-tree-loop-vectorize. It also fails with gcc 5.2, but works
with gcc 4.8, so this is a regression somewhere between those two versions.

Source:
#include <assert.h>
#include <stdio.h>

#define NO_CLONE __attribute__((noclone))
#define NO_INLINE __attribute__((noinline))

NO_INLINE NO_CLONE void TestGCC81740_Sub(int* p, unsigned count)
{
 static const int good[20] = { 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 10, 5, 6, 7, 8,
15, 10, 11, 12, 13 };

 assert(count == 20);

 for(unsigned i = 0; i < count; i++) {
 if (good[i] != p[i]) printf("got %u expected %u (%u)\n", p[i], good[i], i);
  assert(good[i] == p[i]);
  }
}

int TestGCC81740_b;

NO_INLINE NO_CLONE void TestGCC81740(void)
{
 int v[4][5] = { 0 };

 for(unsigned i = 0; i < sizeof(v) / sizeof(int); i++)
  (&v[0][0])[i] = i;

 for(int a = 3; a >= 0; a--)
  for(TestGCC81740_b = 0; TestGCC81740_b < 3; TestGCC81740_b++)
   v[TestGCC81740_b + 1][a + 1] = v[TestGCC81740_b][a];

 TestGCC81740_Sub(&v[0][0], sizeof(v) / sizeof(int));
}


int main() {
  TestGCC81740();
  return 0;
}

Reply via email to