-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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.
thvdveld, SergeyKasmy, EkremDincel, marioortizmanero, rubdos and 5 more
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.