3 ms·
Does someone know how the compiler comes up with the closed form solution? Is there a hardcoded list of common patterns and their solution in the compiler, or i
by echoangle 2y ago
Does someone know how the compiler comes up with the closed form solution? Is there a hardcoded list of common patterns and their solution in the compiler, or is this really generated from the code itself?
- drtc 2y agoI wondered the same thing and found this to be interesting: https://stackoverflow.com/questions/74417624/how-does-clang-generate-non-looping-code-for-sum-of-squares https://stackoverflow.com/questions/74417624/how-does-clang-...
- moomin 2y agoYeah, one suspects this is a dumb micro-optimisation to make benchmark figures look better with little practical application.
- lambdaxyzw 2y agoDoing micro optimizations is precisely the compiler's job - so I don't have to worry about it.
- moomin 2y agoYeah, but all micro optimisations come with costs, from compiler time to maintenance overhead. Someone's still got to ask if it's worth it. And in this case, I just can't see many regular programs containing code likely to trip this, but benchmarks? All the time.
- fooker 2y agoIt's more like a hundred matched patterns, with more added once in a while.