Compiler switch to list bound checks

fd9eb37
Opened by leonardo-m at 2020-07-16 21:45:47

This is my first Rust enhancement request.

With the Go language compiler version 1.7, you can build the code using -gcflags="-d=ssa/check_bce/debug=1" to show which code lines still need checking bounds:

http://www.tapirgames.com/blog/golang-1.7-bce

Finding where the compiler is not able to optimize away run-time bound checks is important for some kinds of code where performance matters:

https://github.com/rust-lang/rust/pull/30917

Currently to do that in Rust I have to generate the asm with --emit asm, search the function(s) (this sometimes is not so easy because of inlining) and then read the asm to understand if and where it performs bound checks. This is a bit laborious and not handy. So is it possible to add to Rustc a compilation switch similar to Go that outputs all the lines and column where LLVM isn't able to remove array bound tests?

In-bound test(s):
16 | foo[i] -= 1;
         ^

32 | foo[i] += bar[j];
         ^         ^

(Having this compiler switch is only about one third of this performance battle).

  1. Awesome idea! I'm not really fluent in asm, let alone fluent enough to know which instruction takes how much time, but I still want to improve performance, and this would make it easier for me.

    est31 at 2016-10-25 14:59:38

  2. Definitely useful but I'm unsure how hard this would be. Most (if not all) of the elimination are done by the llvm optimizer.

    Arthur Silva at 2016-10-26 19:32:28

  3. Triage; not aware of any changes

    Steve Klabnik at 2020-07-16 20:21:25

  4. Perhaps the index_slicing clippy lint partially covers this?

    Matthias Krüger at 2020-07-16 21:45:47