Closed
Description
pub fn f(arr: &mut [u32]) {
for i in 0..arr.len() {
for j in 0..i {
assert!(j < arr.len());
}
}
}
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
void f(int *ptr, size_t len) {
for (size_t i = 0; i < len; i++) {
for (size_t j = 0; j < i; j++) {
assert(j < len);
}
}
}
GCC is also able to remove the assert with GCC trunk.
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Issue: Problems and improvements with respect to performance of generated code.Relevant to the compiler team, which will review and decide on the PR/issue.