Compilers are extremely good considering the amount of crap they have to churn through but they have zero information (by default) about how the program is going to be used so it's not hard to beat them.
If anyone is curious to learn more, look up "profile-guided optimization" which observes the running program and feeds that information back into the compiler