Issue 63893
Summary Wrong code at -O2 on x86_64-linux_gnu (a recent regression in Two-Address instruction pass)
Labels
Assignees
Reporter shao-hua-li
    This looks like a recent regression. Clang at -O2 produces the wrong code. `opt-bisect-limit` suggests that the issue might be in ` Two-Address instruction pass`. 

Compiler explorer: https://godbolt.org/z/G6vxTTzPr

```console
% cat a.c
int printf(const char *, ...);
short c;
int f, q = 3, r, t, z, ae_y;
char g, b, h, m, o, s;
static long i_0_0 = 23772937180;
static char *j = &b;
static  char **k[5] = {&j};
static  char ***l = &k[4];
long n;
static long *p = &i_0_0, *e = &i_0_0;
int *ae(int *ad) {
  long u;
  int *v = &f;
af:
  for (;;) {
    *j = 8;
    int w;
    for (; o; o--)
      if (*j + *p + g)
 goto af;
    if (*ad)
      ;
    else{
      for (; t <= 1; t++) {
        int *x = &r;
        for (;; s++) {
          *v = 9;
 if (q + *ad)
            break;
        }
        if (g)
 goto af;
        for (; s + m; m++)
          ;
        u = *e;
        *e = (unsigned)u;
        *x ^= (int)n + m;
        *v = c;
        if (*v)
          ;
        else {
          ad = &ae_y;
          return x;
        }
      }
    }
    for (; h;)
      ;
  }
}
void ag() {  char ****a[] = {&l, &l}; }
int main() {
  ae(&z);
  printf("%ld\n", i_0_0);
}
%
% clang-tk -O0 a.c && ./a.out
2298100700
%
% clang-tk -O2 a.c && ./a.out
23772937180
%
% clang-tk -v
clang version 17.0.0 (https://github.com/llvm/llvm-project.git 46333f71f8e0d6444a9b2c9e063aedb83ebb9735)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /zdata/shaoli/compilers/ccbuilder-compilers
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
%
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to