Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> If people expect that pow(x,2) transforms to x * x, then every compiler would have to implement that. This is a trivial example, but you in reality you always have to structure your code appropriately for some optimization to kick in, what if one of your target compilers needs a different structure?

Do you get your copy of Hacker's Delight off the bookshelf to look up the magic number instead of writing "x / 3"?

Everyone relies on optimizations to some extent. It's simply infeasible to do otherwise.



I'm not saying compilers shouldn't optimize, they just shouldn't try to be clever. Some things can be expected to be done by most any compiler, many things are extremely compiler-specific and only work under very specific circumstances.


I agree that there is a line beyond which you shouldn't expect compilers to optimize. But "being clever" is responsible for lots of seemingly-simple optimizations. If you want something to blame, blame the C language for making program transformations hard due to unrestricted aliasing and so forth. Don't blame compiler authors for responding to the demands of their users.


Taken to its logical conclusion this is an argument that things should never change and never try to get better.

Clearly that is not what you mean and is not a good thing. Perhaps optimizing compilers put you outside of your comfort zone because you think they force you to learn and keep up to date.

You can do that or you can stick to writing idiomatic code that uses the std library for a given compiler. Doing just this tends to produce extremely good results. I often outdo others near just with this when they are dropping to assembly or doing silly workarounds because they know something is slow. Profiling and timing are required to pick up the rest of the performance, and presuming otherwise is silly. No special knowledge of the machine or compiler is required, just a knowledge of when and how to optimize and when and how to write idiomatically.


[flagged]


Posting uncivilly will get you banned regardless of how wrong the other person was, so please don't comment like this.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: