It seems like compilers should have an interactive mode where it suggests code that is very similar but not technically perfectly the same that is more efficient and the can accept or decline the alternate version.
A backend compiler is probably not in a good place to do that. Frontends could, however, and there are lots of tools already to make those suggestions for many languages.
clippy in rust, for example, will tell you about removing needless allocations, etc, which a backend compiler might have a harder time doing.