> I understand that a JIT engine cant do this, due to speed.
Most serious JIT engines do! For example V8, LuaJIT, Graal, C2.
> But would be surprised that a LLVM compiler with a custom-designed heuristic for specific optimizations cant manage this.
Rubinius for example tried writing custom optimisations like you're describing and didn't get very far. LLVM is not designed for these kind of optimisations - it understands memory reads and writes, not high-level semantic information about arrays and objects.
In practice, it just doesn't seem to work.
As I say I think it's a bare minimum for making a dynamic language genuinely fast. I gave a lecture about this https://www.youtube.com/watch?v=b1NTaVQPt1E.