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

Implement attributes for branch weight #11092

Closed
kvanbere opened this issue Dec 21, 2013 · 4 comments
Closed

Implement attributes for branch weight #11092

kvanbere opened this issue Dec 21, 2013 · 4 comments
Labels
I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@kvanbere
Copy link

The cold attribute exists for functions, but one might want to put weights on branches. This could have 3 forms; weight=N where N is 0-1, likely (1) and unlikely (0).

LLVM understands these annotations on branches already and can use these to fine-tune assembly to reduce branch mis-predictions. By nature, these could be used extensively in the standard library.

ie

match leaf {
    #[likely]
    Some(x) => recurse(x),
    None => {
        // do stuff that doesn't make sense to be in a cold fn
        ...
    }
}

There have been cases in Haskell libraries where changing the order of ADTs can increase performance by around 20% because branches are guessed differently by the compiler.

@pmarcelll
Copy link
Contributor

#36181 added likely and unlikely intrinsics.

@cyplo
Copy link
Contributor

cyplo commented Oct 12, 2016

Hi ! With #36181 being merged, it there any other changes needed to close this one ? Thank you !

@aturon
Copy link
Member

aturon commented Apr 15, 2017

Closing for the time being due to #36181.

@aturon aturon closed this as completed Apr 15, 2017
@Eh2406
Copy link
Contributor

Eh2406 commented Jun 8, 2018

There is a reference to this issue in the code:

// Annotate exceedingly likely branches in `table::make_hash`
// and `search_hashed` to reduce instruction cache pressure
// and mispredictions once it becomes possible (blocked on issue #11092).

What needs to be done to remove that comment, now that this is closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

No branches or pull requests

6 participants