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

            Bug ID: 78652
           Summary: LRA generates wrong code by inheriting changed
                    register
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: amker at gcc dot gnu.org
  Target Milestone: ---

Hi, given below sample code:

extern int printf(const char *, ...);

short a, b = 1, p, t;
struct {
  signed f1 : 9;
} m = {3};

int c, g = 0, h = 8, i, k, l, q, r, s, w, x = 9;
long long d = 1;
long long e = 1;
char f[9][6][4] = {{{1}}};
short j[6] = {1};

unsigned n;
static long long *o = &e;
char u;
short *v;
char *y = &f[6][4][3];
short fn1(short p1) { return a == 0 ? p1 : p1 % a; }

static int *fn2(signed char p1, int p2, signed char p3) {
lbl_2057:
  if (n >= (q >= fn1(3)))
    return &r;
  if (p2)
    t = u;
  *v = (t | *o) * p2;
  for (;;) {
    for (; u <= 1;)
      goto lbl_2057;
    if (p1)
      s = g = 0;
  }
}

void fn3(int *p1) {
  if (*p1)
    ;
  else {
    x = w;
    for (;;)
      ;
  }
}

int *fn4(long p1) {
  for (; p1; p1--)
    e = 1;
  y = 0;
  return &h;
}

__attribute__((section(".text")))
int main() {
  int *z;
  long t1;
  long long *t2 = &d;
  *t2 = b;
  z = fn4(*t2);
  fn3(z);
  short *t3 = &j[0];
  *t3 = f[6][4][3] >= (b = i);
  t1 = p < n;
  fn2(c < t1 >= m.f1, l, k);
  j[5]++;
  printf("result = %X\n", m.f1);
}

Compiled/run with below command line on arm-none-eabi:
$ arm-none-eabi-gcc -march=armv7-a -fno-strict-aliasing test.c -o test.exe
-specs=aprofile-validation.specs -O2
$ ./test.exe
result = 1

Which should be:
result = 3

This doesn't happen with O1.

Reply via email to