-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Missed optimization because of missing inline attr on OsStr #67150
Comments
I think the bigger problem here is that the quite trivial AsRef and PartialEq implementations did not get inlined. I would not expect anything to optimize well without those getting inlined. |
I'm not sure we can expect these two to give you the same assembly. They are actually a bit different -- the first one will construct As for the differences in the assembly wrt. comparisons themselves, this seems to be due to the difference between the code to check for equality of I wonder, do you have a particular benchmark/workload where the first function is slower than expected? |
Still, if I change the first snippet like below, the asm is different too: use std::ffi::OsStr;
pub fn foo(s: Option<&OsStr>) -> bool {
let so = OsStr::new("so");
s.map_or(false, |x| x == so)
} |
Inlining does not happen because we do happen to have generated machine code for these trivial functions in libstd.rlib. Tacking some |
After inlining some methods in #67169, I got the same asm between those two snippets: check_stage1::foo:
xor eax, eax
test rdi, rdi
je .LBB0_5
cmp rsi, 2
jne .LBB0_5
lea rax, [rip, +, .Lanon.7bddf4f09674752ba4bdf737f126bcf4.0]
cmp rdi, rax
je .LBB0_3
movzx eax, word, ptr, [rdi]
cmp eax, 28531
sete al
.LBB0_5:
ret
.LBB0_3:
mov al, 1
ret |
Godbolt link: https://rust.godbolt.org/z/bAU2UA
I expect these two snippets have the same optimized asm but they don't:
The text was updated successfully, but these errors were encountered: