The compiler doesn't know the dynamic state of the CPU memory hierarchy and you don't want it to. Even the CPU doesn't know until it finds out how long a load will take.
Meanwhile the CPU probably can't do a loop invariant hoist in a reasonable way or understand high level semantics.
Meanwhile the CPU probably can't do a loop invariant hoist in a reasonable way or understand high level semantics.