-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust unable to optimize away assert vs. clang. #93036
Comments
More generally, rust/llvm does not understand that inequality is transitive. The following code generates three inequality asserts in the assembly: pub fn cmp(a: u32, b: u32, c: u32) {
assert!(a < b);
assert!(b < c);
assert!(a < c);
} Rust playground: https://play.rust-lang.org/?version=stable&mode=release&edition=2021&gist=8cfdb982df6b7e781b398b9408b3cd10 |
Adding |
but not if the types are changed to |
Assuming you need this for slicing then creating a temporary works. pub fn f(arr: &mut [u32]) {
for i in 0..arr.len() {
let subslice = &arr[0..i];
for j in 0..subslice.len() {
assert!(j < subslice.len());
}
}
} |
Since llvm/llvm-project#53273 is now fixed, when is this going to land into nightly Rust (I have no idea when Rust updates LLVM)? And should it fix the origin issue? |
This still requires ConstraintElimination to be enabled on the LLVM side. If it is, then this will land with the LLVM 15 upgrade in ~August. |
this is fixed in latest stable rustc 1.73 see https://rust.godbolt.org/z/G1E35e375 |
Add codegen tests for E-needs-test close rust-lang#36010 close rust-lang#68667 close rust-lang#74938 close rust-lang#83585 close rust-lang#93036 close rust-lang#109328 close rust-lang#110797 close rust-lang#111508 close rust-lang#112509 close rust-lang#113757 close rust-lang#120440 close rust-lang#118392 close rust-lang#71096 r? nikic
Add codegen tests for E-needs-test close rust-lang#36010 close rust-lang#68667 close rust-lang#74938 close rust-lang#83585 close rust-lang#93036 close rust-lang#109328 close rust-lang#110797 close rust-lang#111508 close rust-lang#112509 close rust-lang#113757 close rust-lang#120440 close rust-lang#118392 close rust-lang#71096 r? nikic
Add codegen tests for E-needs-test close rust-lang#36010 close rust-lang#68667 close rust-lang#74938 close rust-lang#83585 close rust-lang#93036 close rust-lang#109328 close rust-lang#110797 close rust-lang#111508 close rust-lang#112509 close rust-lang#113757 close rust-lang#120440 close rust-lang#118392 close rust-lang#71096 r? nikic
Add codegen tests for E-needs-test close rust-lang#36010 close rust-lang#68667 close rust-lang#74938 close rust-lang#83585 close rust-lang#93036 close rust-lang#109328 close rust-lang#110797 close rust-lang#111508 close rust-lang#112509 close rust-lang#113757 close rust-lang#120440 close rust-lang#118392 close rust-lang#71096 r? nikic
Rustc does not optimize away the the assert. Adding
-C passes=constraint-elimination
doesn't help.However, clang does optimize away this assert when compiled with
-O2 -mllvm -enable-constraint-elimination
GCC is also able to remove the assert with GCC trunk.
The text was updated successfully, but these errors were encountered: