-
Notifications
You must be signed in to change notification settings - Fork 210
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
Test failures with newer versions of clang/gcc using O1 and O2 #635
Comments
After looking a bit more into this, it seems like it happens when non initialized I don't know why MSVC has no issue with it, but it seems like clang and gcc are both taking advantage and optimize away some parts.
|
Hi @anthony-linaro @pbo-linaro I am trying to set up CI to cover more compilers. Whether do you guys know some repos I can refer how to run CI with multiple c compiler on ARM machine? |
It's not necessarily needed to have access to an ARM machine. What is missing today is to run CI with optimizations enabled ( |
I will add the optimizations enabled tests, but in case of other potential issues, I am thinking may be testing with more versions of compilers is a good idea |
It's a good idea indeed! LLVM offer convenient debian/ubuntu repositories to grab latest version. |
Hi @anthony-linaro @pbo-linaro sorry to answer late. I am curious the way you identify the errors are caused by strict aliasing rule? __asm__ __volatile__("vmrs %0, FPSCR" : "=r"(r.value)); /* read */ is called. I think maybe the optimization option change the order or ignore this part? |
In general, errors appearing with optimizations enabled are due to undefined behavior (especially when different compilers trigger errors - clang and gcc in our case). When I took a look at the code, I noticed that 128bits integers were stored under an gcc strict aliasing warning can have false positives, but it confirmed that something could be wrong: About the error left, I don't have bandwidth to investigate now, but I suggest that you look at generated assembly code for concerned tests (using Hope this helps! |
I still can't identify the error. Here is the minimal test that produce the same error
The compile command is $ gcc -Wall -Wcast-qual -Wstrict-aliasing=1 -O3 -g -I. -std=gnu11 -march=armv8-a+fp+simd main.c -lm -o main If there only one rounding method is used (in the above one is two), the test can pass. I guess this could be the reason. |
Thanks for reducing the test case. I investigated this using clang. At I noticed that deactivating optimization on variable
By comparing the assembly generated ( What happens is that the compiler has no idea that you changed the default rounding mode (by setting I didn't look as extensively gcc generated code, but I'm pretty sure we just see a compiler optimizing code without knowing the semantic of rounding mode. I tried setting fp rounding using standard function I don't see which portable solution can be used to guarantee a compiler won't do those optimizations (playing with volatile may work, but it's not what we want). I would avoid to change the rounding mode in the middle of a function, and perform computations associated to a given rounding mode in a separate function, marked non inline. Another very expensive solution would be to replace all use of compilers builtin in sse2neon with inline assembly code, to prevent the compiler from optimizing those instructions away. But I'm really not sure it's the right solution to solve this. Program generally set rounding mode once, and don't play with it all the time, it's really a special case. At this point, I would find interesting to raise this issue on llvm project, or gcc mailing list if you want to dig further. |
@pbo-linaro Thank you for the super informative explanation. It is a valuable opportunity to broaden the field I didn't experience, and I think that would be cool to report to llvm and gcc. @jserv what do you think? |
You can definitely try that and check tests now work on all optimization levels with gcc and clang. Another solution is to disable optimization explicitly for functions that manipulate the rounding mode (see this). It is probably more reliable than playing with volatile. |
I agree with the option to disable optimizations for certain rounding-specific functions. It can be applied with some GCC attributes. |
#640 is considered as a feasible solution. @anthony-linaro, please check if it fits. |
Good work! I can still observe some failures:
|
Thank you for testing. I will fix them together with I think some of them may cause by breaking the strict-aliasing rules |
After having a little more of a dig in relation to #633 - it appears that tests are failing on all platforms, including linux, when using newer versions of clang (tested against LLVM 14 through to LLVM 18), and using higher optimization levels.
GCC also has a subset of these failures.
This is reproducible on Linux (WSL - below) and Windows (#633).
A log (thanks to @pbo-linaro) is as follows:
Nothing suspect is returned by
fsanitize=address
orfsanitize=undefined
.At this point it's a little beyond my level of expertise with SIMD/NEON, so it would be appreciated if someone a little more versed could have a look.
The text was updated successfully, but these errors were encountered: