-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Poorly optimized assembly generation around Ipv4Addr, Ipv6Addr #77583
Comments
Maybe it's just missing |
I will try to test with adding |
This is a trivial method on a concrete type, so yeah, probably just needs (If it were generic it wouldn't be necessary, but for concrete things the bodies aren't in the meta.) |
So I found when a crate exports a function with fn main() {
let ip: Ipv4Addr = std::env::args().nth(1).unwrap().parse().unwrap();
let ipbeu32 = u32::from_be_bytes(ip.octets());
let net = Ipv4Addr::from((ipbeu32 & 0xffffff00u32.to_be()).to_ne_bytes());
println!("{}", net);
} Edit: copy the right "basic program" this time... With Is this worth a PR to add |
Feel free to open a PR I guess, your reviewer will decide whether it should be merged or not. |
Ping @TyPR124, do you want to work on fixing this issue? |
…ine-for-ip, r=m-ou-se Add `#[inline]` to IpAddr methods Add some inlines to trivial methods of IpAddr Closes rust-lang#77583
…ine-for-ip, r=m-ou-se Add `#[inline]` to IpAddr methods Add some inlines to trivial methods of IpAddr Closes rust-lang#77583
…ine-for-ip, r=m-ou-se Add `#[inline]` to IpAddr methods Add some inlines to trivial methods of IpAddr Closes rust-lang#77583
…ine-for-ip, r=m-ou-se Add `#[inline]` to IpAddr methods Add some inlines to trivial methods of IpAddr Closes rust-lang#77583
I tried this code:
I expected to see this happen: assembly generated should be equivalent to:
Instead, this happened: the generated assembly retains calls to Ipv4::octets and Ipv4::from, leaving the assembly poorly optimized
I've played with different ways of implementing the safe version, but cannot find anyway get it to optimize further.
Good assembly:
Bad assembly:
Playground and GodBolt (both include an IPv6 example as well)
Adding '-Z mir-opt-level=2' (or higher) does optimize away the call to octets, but not the call to from.
I get the same optimization behavior when building a binary, at least on my own platfom (x86-64 Windows MSVC)
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: