Skip to content

[NewGVN] wrong code at Os and above with -mllvm -enable-newgvn #56149

Open
@zhendongsu

Description

@zhendongsu

This appears to affect clang 5.* and later, so a quite long-latent regression.

% clangtk -v
clang version 15.0.0 (https://github.com/llvm/llvm-project.git 4d2eda2bb3156cee63ea486be34b01164b178e10)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /local/suz-local/opfuzz/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
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/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
% 
% clangtk -O0 small.c; ./a.out
% clangtk -O3 small.c; ./a.out
% 
% clangtk -O3 -mllvm -enable-newgvn small.c
% timeout -s 9 5 ./a.out
Killed
% 
% cat small.c
int printf(const char *, ...);
int a;
short b;
int main() {
  short d = 0;
  a = 9;
  for (; a > 5; a--)
    ;
  short e = a;
  void *f();
  if (e < 7) {
  L:
    d = a;
    a = ~(d & (&f || a));
  }
  while (a >= d)
    ;
  while (a == d)
    printf("0");
  if (b <= a)
    goto L;
  return 0;
}

Compiler Explorer: https://godbolt.org/z/sT1G5seEP

Metadata

Metadata

Assignees

No one assigned

    Labels

    llvm:GVNGVN and NewGVN stages (Global value numbering)miscompilation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions