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. 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": 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 godbolt.org/z/fe641sK1a

Code for the pass is here: github.com/llvm/llvm-project/b

Sign in to participate in the conversation
Mastodon

a Schelling point for those who seek one