-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
clang generates unoptimal code for code with lots of temporary variables #78506
Comments
You may help compiler by providing information about possible values of Also, is it supposed to be Here are some loop versions https://godbolt.org/z/571aPj9zh, when written as loop all spills are gone. Somehow both compilers fail to use the fact that |
Another weird example, setting aligned value to 8 or higher brings a lot of spills in Clang https://godbolt.org/z/EKExxvxv3 |
Originally this was a circular shift, so I guess that is an optimization. |
If anyone wants to play with the directly unrolled version (even though LLVM seems to like fully unrolling this loop anyway) $0 ~ /^##.*/ {gsub("^## ",""); print}
$0 ~ /^#~.*/ {gsub("^#~ ",""); gsub("N",N); if($0 ~ /?/) {for (i=1; i<N; i++) {a = $0; gsub("?",i,a); print a}} else {print}}
## #include <stddef.h>
## #define assume(x) if (!(x)) { __builtin_unreachable(); }
## struct wtf {
#~ int a[N];
## };
## struct wtf __attribute__ ((noinline)) foo(struct wtf *b, int i)
## {
#~ assume(i >= 0 && i < N);
## struct wtf new;
#~ int idx? = (? + i) % N ;
#~ int val? = b->a[idx?] ;
#~ new.a[?] = val? ;
## return new;
## }
## usage with |
I started a discussion in discourse but I think this might be worthy of an issue, I know the code looks strange but it's a C reproducer of what julia generates.
This code when compiled with gcc 12 is about 40% faster than what clang-17 generates, and by allowing it to inline it becomes around 60% faster, a quick peak at the assemblies shows a very different piece of code, with gcc using mostly xmm register and avx instructions while clang uses mostly normal registers.
https://godbolt.org/z/nWrKKe7s9
The text was updated successfully, but these errors were encountered: