Skip to content

[LoongArch] Miscompile with O3 #114578

@dtcxzyw

Description

@dtcxzyw

Reproducer:

int printf(const char *, ...);
int a;
long b = 1;
short c, d;
void e(short f) {
ab:
  d = f == b ?1: b % f;
  if (d)
    c = 0;
  for (; c <= 0; c++) {
    if (c)
      goto ab;
    a++;
  }
}
void g() {
  short h = 15;
  for (; h; --h) {
    e(h);
    e(11);
  }
}
int main() {
  g();
  printf("%d\n", a);
}
> gcc -O0 test.c && ./a.out
30
> clang -O3 test.c && ./a.out
29

llvm version: 8951b51

Metadata

Metadata

Assignees

Labels

llvm:analysisIncludes value tracking, cost tables and constant foldingllvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmiscompilation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions