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

Question from a frontend dev: Why can't the compiler apply these tricks automatically? Are there assumptions they're making that don't necessarily hold?


Clang and GCC can do some amazing optimizations. However, these types of tricks often come into play as a result of clever data representation, i.e., instead of representing data as a bunch of objects in an array, you’ve figured out how to represent it, or a subset, in some cleverly packed bits and/or ints (and then can reap the benefit of these tricks).

It’s trivial for a compiler to see (x / 2) and substitute (x >> 1) but it is much harder for a compiler to go from seeing that you have a bunch of Foo objects and realizing that they could be better represented as clever bit vectors.


You can't really trust the compiler to emit sensible code ever


The compiler cannot always detect all the uses.




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

Search: