-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RISCV] When enabling -force-vector-width
, RVV vectorization has produced wrong results
#77044
Comments
@llvm/issue-subscribers-backend-risc-v Author: Shao-Ce SUN (sunshaoce)
```shell
clang foo.c -w -lm -mllvm -force-vector-width=16 -mllvm -force-vector-interleave=2 --target=riscv64 -march=rv64gcv -O3 --gcc-toolchain=$HOME/riscv --sysroot=$HOME/riscv/riscv64-unknown-elf
```
#include <malloc.h>
#include <stdio.h>
float foo() {
#define LEN 10000
float a[LEN];
float ret = 0.;
for (int i = 0; i < LEN; i++) {
a[i] = 1 + i;
ret += a[i];
}
return ret;
}
int main(int argc, char **argv) { printf("%f\n", foo()); } I got the wrong result.
Then I tested several other compilers(gcc, clang on x86) and got the same results.
Disabling |
@llvm/issue-subscribers-bug Author: Shao-Ce SUN (sunshaoce)
```shell
clang foo.c -w -lm -mllvm -force-vector-width=16 -mllvm -force-vector-interleave=2 --target=riscv64 -march=rv64gcv -O3 --gcc-toolchain=$HOME/riscv --sysroot=$HOME/riscv/riscv64-unknown-elf
```
#include <malloc.h>
#include <stdio.h>
float foo() {
#define LEN 10000
float a[LEN];
float ret = 0.;
for (int i = 0; i < LEN; i++) {
a[i] = 1 + i;
ret += a[i];
}
return ret;
}
int main(int argc, char **argv) { printf("%f\n", foo()); } I got the wrong result.
Then I tested several other compilers(gcc, clang on x86) and got the same results.
Disabling |
Forcing vectorization enables some FP reassociation even without -fast-math. X86 with -O0 gives 50002896.000000, but with forced vetorization I got 50004992.000000. So I'm not sure what the right answer is. |
I got 50004992.000000 with |
Bisect to
after (50005000.000000):
cc @fhahn |
I'm pretty sure this is known vectorizer behavior. You can disable it with |
Using |
I got the wrong result.
Then I tested several other compilers(gcc, clang on x86) and got the same results.
Disabling
-force-vector-width
can avoid this issue.The text was updated successfully, but these errors were encountered: