| Issue |
240150
|
| Summary |
[LoopVectorize] Wrong result at -Os for loop assigning (unsigned long)i << 63
|
| Labels |
generated by fuzzer
|
| Assignees |
|
| Reporter |
hazohelet
|
Live Reproducer: https://godbolt.org/z/3v1W3fnYe
Compiling the following C code with `clang -Os -march=x86-64-v3` and running it prints the wrong result.
```c
#include <stdio.h>
static volatile unsigned A = 3, B = 1;
int main(void) {
unsigned long r = 0;
unsigned n = A, m = B, i;
for (i = 0; i < n; i++)
if (m)
r = (unsigned long)i << 63;
printf("%lu\n", r);
}
```
clang command:
```sh
clang -Os -march=x86-64-v3 repro.c && ./a.out
```
Output (wrong):
```text
9223372036854775808
```
Expected (what -O0 prints, and what GCC 16 prints at -O0, -O2, -O3 and -Os):
```text
0
```
`m` is 1, so `r` is assigned on every iteration and holds the value of the last one, `2 << 63`, which is 0.
Notes:
* Correct at -O0, -O1, -O2, -O3 and -Oz
* Correct with `-fno-vectorize`
* Also wrong for `--target=aarch64-linux-gnu -Os`
clang version:
```text
clang version 24.0.0git (https://github.com/llvm/llvm-project 3a34e810f3844371c6fa1f164741cf22c3c513ff)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs