It's frustrating that LLVM can't eliminate this array bounds check even though it can prove the inner loop asserts can be eliminated. It looks like the problem is that the bounds check is being expressed as an equality check of the bytewise index. https://godbolt.org/z/n7bEjE735
Turns out this is fixed by LLVM's new constraint elimination pass, which is enabled by default in LLVM trunk but can be enabled manually in rustc right now with -C llvm-args="-enable-constraint-elimination": https://godbolt.org/z/MzTrhr4bM
You still need to add the explicit assert in the loop body to guide the constraint elimination. That is odd; there must be something about Rust's lowering of the loop that confuses it versus https://godbolt.org/z/fe641sK1a
Code for the pass is here: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp