-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fixes #25109; fixes #25111 transform addr(conv(x))
-> conv(addr(x))
#25112
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
Conversation
addr ( conv ( x ) )
-> conv ( addr ( x ) )
addr(conv(x))
-> conv(addr(x))
Thanks for your hard work on this PR! Hint: mm: orc; opt: speed; options: -d:release |
This transformation (still) looks like it will violate strict aliasing, similar to #24818 (comment) .. |
ie maybe on the nim side, this is fine, but it's not a valid transformation to make in C - even if two integers have the same byte size, they are not the same type and therefore may not alias - instead, one has to either union or memcpy values |
void main(NU64* v) {
unsigned long long tmp = (unsigned long long)(*v);
foo(&tmp);
*v = tmp
} This seems to much harder to be transformed into. Perhaps I can improve it with |
We don't care about aliasing though, it's impossible to use properly for a code generator (and also for most mortal beings). |
the C optimiser does though - and in this particular case, there exists a translation that is both correct, alias-free and fairly simple - it just requires using a different technique than casting on the C side. |
Why not apply #25067 then? |
Maybe but I think it's just a whack-a-mole game. I also think the C compilers themselves cannot really follow C's aliasing rules as too much realworld C code would simply break... |
It's just a set of rules - they're fairly consistent and can be summarized as "copy, don't cast when in doubt" - and yes, optimizers do use them to optimize code, and more aggressively so when you enable LTO - Nim is in particular affected due to how nim spreads implementations all over the place with generics - but in return, you get a 20-30% performance improvement, for simply following the language rules. #24596 is a real-world example. |
follows up #24818
relates to #23923
fixes #25109
fixes #25111
transform
addr ( conv ( x ) )
->conv ( addr ( x ) )
so that it is the original value that is being modified