You can't fool the optimizer
xania.org
You can't fool the optimizer
1–10 of 193 posts
Re: You can't fool the optimizer
#2Re: You can't fool the optimizer
#3See "Example 2: Tricking the compiler" in my blog post about O3 sometimes being slower than O2: https://barish.me/blog/cpp-o3-slower/
Re: You can't fool the optimizer
#4You absolutely can fool a lot of compilers out there! And I am not only looking at you, NVCC.
Re: You can't fool the optimizer
#5I always code with the mindset “the compiler is smarter than me.” No need to twist my logic around attempting to squeeze performance out of the processor - write something understandable to humans, let the computer do what computers do.
Like with people in general, it depends on what compiler/interpreter we're talking about, I'll freely grant that clang is smarter than me, but CPython for sure isn't. :)
More generally, canonicalization goes very far, but no farther than language semantics allows. Not even the notorious "sufficiently smart compiler" with infinite time can figure out what you don't tell it.
Re: You can't fool the optimizer
#6Re: You can't fool the optimizer
#7I always code with the mindset “the compiler is smarter than me.” No need to twist my logic around attempting to squeeze performance out of the processor - write something understandable to humans, let the computer do what computers do.
Re: You can't fool the optimizer
#8E.g. if in `main` you called two different add functions, couldn't it optimize one of them away completely?
It probably shouldn't do that if you create a dynamic library that needs a symbol table but for an ELF binary it could, no? Why doesn't it do that?
Re: You can't fool the optimizer
#9Re: You can't fool the optimizer
#10I always code with the mindset “the compiler is smarter than me.” No need to twist my logic around attempting to squeeze performance out of the processor - write something understandable to humans, let the computer do what computers do.
pareto principle like always, dont need the best but good enough
not every company is google level anyway