Issue 208944
Summary wrong code at -O{s,2,3} with "-ffp-contract=fast" on x86_64-linux-gnu
Labels new issue
Assignees
Reporter zhendongsu
    Compiler Explorer: https://godbolt.org/z/j4xYsefz9

Note:
- fails: trunk
- works: 22.1.0 and earlier

```
[686] % clangtk -v
clang version 23.0.0git (https://github.com/llvm/llvm-project.git 184d97baded92622778a701b66e7f148903f3525)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin
Build config: +assertions
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
Found CUDA installation: /usr/local/cuda, version 12.1
[687] % 
[687] % clangtk -O3 small.c; ./a.out
[688] % 
[688] % clangtk -O3 -ffp-contract=fast small.c
[689] % ./a.out
Aborted
```

```
#include <math.h>
#include <stdlib.h>
int a[256], e, j, k, l, m, n, *o, p, q;
int aa(int r, int s) {
  for (int f = 0; f < 256; ++f) {
    unsigned c = f;
 for (int g = 0; g < 8; ++g)
      c = c & 1 ? c >> 1 ^ 3988292384 : c >> 1;
    a[f] = c;
  }
  unsigned h = r;
  int i = s;
  for (int b = 0; b < 4; ++b) {
    char d = i;
    i >>= 8;
    h = h >> 8 ^ a[(h ^ d) & 255];
  }
  return h;
}
int t(short r, float s, short u, int v) {
 float w, x;
  o = &k;
  do {
    x = 1 + s;
    if (!isfinite(x))
 abort();
    if (!s)
      abort();
    x = -1.125f * s + 0;
    if (!isfinite(x))
      abort();
    j = -99;
    m = -3146541 - ((long)((unsigned long)r << 48) >> 48);
    w = 2.0f - s;
    if (!isfinite(w))
      abort();
    w = 0 + 2.0f * s;
  } while (!isfinite(w));
  k = 919 / r;
  l = m;
  if (u) {
    e = -92 - k;
 x = 0;
  }
  m = 1078592145 + ((long)((unsigned long)e << 56) >> 56);
  n = aa(0, (long)((unsigned long)e << 56) >> 56);
  n = aa(n, 1);
  n = aa(n, 1);
  n = aa(n, 1);
  n = aa(n, w);
  n = aa(n, k);
  n = aa(n, l);
  n = aa(n, (long)((unsigned long)j << 56) >> 56);
  n = aa(n, x);
  n = aa(n, m);
  n = aa(n, 0);
  n = aa(n, (long)((unsigned long)r << 48) >> 48);
  n = aa(n, s);
  n = aa(n, u);
  n = aa(n, (long)((unsigned long)v << 44) >> 44);
  p = *o;
  n = aa(n, p);
  q = *o;
  n = aa(n, q);
  return n;
}
int main() {
  if (t(-815, -851940.0f, 2, 524288) != 940039550)
 abort();
  return 0;
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to