*This* is why LLVM is the compiler backend of choice today. It has tons of clever optimisations: