Closed
Description
In code like the following, the compiler misses a possible optimization: in f1
, the length of dst
is equal to the length of bytes
, yet the compiler generates a call to len_mismatch_fail
.
pub fn f1(a: &mut [u8], offset: usize, bytes: &[u8]) {
if let Some(dst) = a.get_mut(offset..offset + bytes.len()) {
dst.copy_from_slice(bytes);
}
}
The compiler knows the lengths are equal (and thus, the panic is unreachable), because the following snippet optimizes the panic away:
pub fn f2(a: &mut [u8], offset: usize, bytes: &[u8]) {
if let Some(dst) = a.get_mut(offset..offset + bytes.len()) {
assert!(dst.len() == bytes.len());
dst.copy_from_slice(bytes);
}
}
This is a regression between rustc versions 1.51 and 1.52.
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Category: This is a bug.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.Performance or correctness regression from one stable version to another.
Activity
[-]`slice::get[_mut]()` followed by `slice::copy_from_slice` generates unreachable panic branch[/-][+]`slice::get_mut()` followed by `slice::copy_from_slice` generates unreachable panic branch[/+]steffahn commentedon Jul 27, 2022
@rustbot label I-slow, E-needs-bisection
steffahn commentedon Aug 30, 2022
This seems to be fixed on nightly. @rustbot label E-needs-test
Bisection would still be interesting IMO, both for the regression and the fix.
steffahn commentedon Aug 30, 2022
Alright, that’s pretty boring in terms of rustc-bisection: it was fixed by #99464 (Update to LLVM 15), and it regressed in
nightly-2021-03-05
which includes #81451 (Upgrade1 to LLVM 12).@rustbot label -E-needs-bisection, +A-llvm.
Footnotes
what’s up with the inconsistent naming, upgrade vs. update? ↩
Add test for rust-lang#98294
7 remaining items