It seems to me that if I were due to release some software, I would hand-optimize the code before running it through the compiler, where those optimizations would be purely for that release and not part of the main code repository. Once I had compiled and released the code, I would then continue to develop the main repository and only introduce the optimizations when compiling for release.

Could a compiler have some kind of mega-optimization option, or could there be a separate optimization program, that could work for minutes or hours, and substantially reorganize the code, before giving it to a compiler? Or is it always better to optimize while compiling?