rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.65k stars 12.75k forks source link

Compiler switch to list bound checks #37397

Open leonardo-m opened 8 years ago

leonardo-m commented 8 years ago

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).

est31 commented 8 years ago

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.

arthurprs commented 8 years ago

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

steveklabnik commented 4 years ago

Triage; not aware of any changes

matthiaskrgr commented 4 years ago

Perhaps the index_slicing clippy lint partially covers this?