Skip to content
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

Compiler cant hoist following branch out of loop #544

Open
re0312 opened this issue Aug 19, 2024 · 2 comments
Open

Compiler cant hoist following branch out of loop #544

re0312 opened this issue Aug 19, 2024 · 2 comments

Comments

@re0312
Copy link

re0312 commented Aug 19, 2024

Objectives

Why can't the compiler hoist branch out of the loop in the following code?

use std::hint::black_box;

use hashbrown::HashMap;

pub fn main() {
    let mut map: HashMap<u32, u32> = hashbrown::HashMap::default();
    map.insert(0, 0);
    
    for i in 0..10000 {
        if let Some(_) = map.get(&0) {
            continue;
        } else {
            black_box(i);
        }
    }
}

online assembly https://rust.godbolt.org/z/vr3WGsfhP

@Amanieu
Copy link
Member

Amanieu commented Aug 21, 2024

This happens because hashbrown::raw::RawTable<T,A>::find is not inlined and therefore LLVM doesn't know that it is a pure function.

@re0312
Copy link
Author

re0312 commented Aug 21, 2024

This happens because hashbrown::raw::RawTable<T,A>::find is not inlined and therefore LLVM doesn't know that it is a pure function.

Thanks for your reply. but I checked the code and it seems that RawTable::find has been marked as inline, and there are no extra call in the assembly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants