-
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
Reexport likely/unlikely in std::hint #133695
Merged
+354
−4
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//@ compile-flags: -O | ||
#![crate_type = "lib"] | ||
#![feature(cold_path)] | ||
|
||
use std::hint::cold_path; | ||
|
||
#[inline(never)] | ||
#[no_mangle] | ||
pub fn path_a() { | ||
println!("path a"); | ||
} | ||
|
||
#[inline(never)] | ||
#[no_mangle] | ||
pub fn path_b() { | ||
println!("path b"); | ||
} | ||
|
||
#[no_mangle] | ||
pub fn test1(x: bool) { | ||
if x { | ||
path_a(); | ||
} else { | ||
cold_path(); | ||
path_b(); | ||
} | ||
|
||
// CHECK-LABEL: @test1( | ||
// CHECK: br i1 %x, label %bb1, label %bb2, !prof ![[NUM:[0-9]+]] | ||
// CHECK: bb2: | ||
// CHECK: path_b | ||
// CHECK: bb1: | ||
// CHECK: path_a | ||
} | ||
|
||
#[no_mangle] | ||
pub fn test2(x: i32) { | ||
match x > 0 { | ||
true => path_a(), | ||
false => { | ||
cold_path(); | ||
path_b() | ||
} | ||
} | ||
|
||
// CHECK-LABEL: @test2( | ||
// CHECK: br i1 %_2, label %bb2, label %bb1, !prof ![[NUM]] | ||
// CHECK: bb1: | ||
// CHECK: path_b | ||
// CHECK: bb2: | ||
// CHECK: path_a | ||
} | ||
|
||
// CHECK: ![[NUM]] = !{!"branch_weights", {{(!"expected", )?}}i32 2000, i32 1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
//@ compile-flags: -O | ||
#![crate_type = "lib"] | ||
#![feature(likely_unlikely)] | ||
|
||
use std::hint::likely; | ||
|
||
#[inline(never)] | ||
#[no_mangle] | ||
pub fn path_a() { | ||
println!("path a"); | ||
} | ||
|
||
#[inline(never)] | ||
#[no_mangle] | ||
pub fn path_b() { | ||
println!("path b"); | ||
} | ||
|
||
#[no_mangle] | ||
pub fn test1(x: bool) { | ||
if likely(x) { | ||
path_a(); | ||
} else { | ||
path_b(); | ||
} | ||
|
||
// CHECK-LABEL: @test1( | ||
// CHECK: br i1 %x, label %bb2, label %bb3, !prof ![[NUM:[0-9]+]] | ||
// CHECK: bb3: | ||
// CHECK: path_b | ||
// CHECK: bb2: | ||
// CHECK: path_a | ||
} | ||
|
||
#[no_mangle] | ||
pub fn test2(x: i32) { | ||
match likely(x > 0) { | ||
true => path_a(), | ||
false => path_b(), | ||
} | ||
|
||
// CHECK-LABEL: @test2( | ||
// CHECK: br i1 %_2, label %bb2, label %bb3, !prof ![[NUM]] | ||
// CHECK: bb3: | ||
// CHECK: path_b | ||
// CHECK: bb2: | ||
// CHECK: path_a | ||
} | ||
|
||
#[no_mangle] | ||
pub fn test3(x: i8) { | ||
match likely(x < 7) { | ||
true => path_a(), | ||
_ => path_b(), | ||
} | ||
|
||
// CHECK-LABEL: @test3( | ||
// CHECK: br i1 %_2, label %bb2, label %bb3, !prof ![[NUM]] | ||
// CHECK: bb3: | ||
// CHECK: path_b | ||
// CHECK: bb2: | ||
// CHECK: path_a | ||
} | ||
|
||
#[no_mangle] | ||
pub fn test4(x: u64) { | ||
match likely(x != 33) { | ||
false => path_a(), | ||
_ => path_b(), | ||
} | ||
|
||
// CHECK-LABEL: @test4( | ||
// CHECK: br i1 %0, label %bb3, label %bb2, !prof ![[NUM2:[0-9]+]] | ||
// CHECK: bb3: | ||
// CHECK: path_a | ||
// CHECK: bb2: | ||
// CHECK: path_b | ||
} | ||
|
||
// CHECK: ![[NUM]] = !{!"branch_weights", {{(!"expected", )?}}i32 2000, i32 1} | ||
// CHECK: ![[NUM2]] = !{!"branch_weights", {{(!"expected", )?}}i32 1, i32 2000} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
//@ compile-flags: -O | ||
#![crate_type = "lib"] | ||
#![feature(likely_unlikely)] | ||
|
||
use std::hint::unlikely; | ||
|
||
#[inline(never)] | ||
#[no_mangle] | ||
pub fn path_a() { | ||
println!("path a"); | ||
} | ||
|
||
#[inline(never)] | ||
#[no_mangle] | ||
pub fn path_b() { | ||
println!("path b"); | ||
} | ||
|
||
#[no_mangle] | ||
pub fn test1(x: bool) { | ||
if unlikely(x) { | ||
path_a(); | ||
} else { | ||
path_b(); | ||
} | ||
|
||
// CHECK-LABEL: @test1( | ||
// CHECK: br i1 %x, label %bb2, label %bb4, !prof ![[NUM:[0-9]+]] | ||
// CHECK: bb4: | ||
// CHECK: path_b | ||
// CHECK: bb2: | ||
// CHECK: path_a | ||
} | ||
|
||
#[no_mangle] | ||
pub fn test2(x: i32) { | ||
match unlikely(x > 0) { | ||
true => path_a(), | ||
false => path_b(), | ||
} | ||
|
||
// CHECK-LABEL: @test2( | ||
// CHECK: br i1 %_2, label %bb2, label %bb4, !prof ![[NUM]] | ||
// CHECK: bb4: | ||
// CHECK: path_b | ||
// CHECK: bb2: | ||
// CHECK: path_a | ||
} | ||
|
||
#[no_mangle] | ||
pub fn test3(x: i8) { | ||
match unlikely(x < 7) { | ||
true => path_a(), | ||
_ => path_b(), | ||
} | ||
|
||
// CHECK-LABEL: @test3( | ||
// CHECK: br i1 %_2, label %bb2, label %bb4, !prof ![[NUM]] | ||
// CHECK: bb4: | ||
// CHECK: path_b | ||
// CHECK: bb2: | ||
// CHECK: path_a | ||
} | ||
|
||
#[no_mangle] | ||
pub fn test4(x: u64) { | ||
match unlikely(x != 33) { | ||
false => path_a(), | ||
_ => path_b(), | ||
} | ||
|
||
// CHECK-LABEL: @test4( | ||
// CHECK: br i1 %0, label %bb4, label %bb2, !prof ![[NUM2:[0-9]+]] | ||
// CHECK: bb4: | ||
// CHECK: path_a | ||
// CHECK: bb2: | ||
// CHECK: path_b | ||
} | ||
|
||
// CHECK: ![[NUM]] = !{!"branch_weights", {{(!"expected", )?}}i32 1, i32 2000} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be expanded a bit? What happens if you use it outside (presumably, nothing)? Can this be used in a
&&
or||
expression?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it would be good to point people to
cold_path
(for which we just approved the ACP) for generalmatch
andif let
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I also export
cold_path()
in this PR, or create a new PR for that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do it in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also added a test for
cold_path()
, but not with idiomatic Rust such asif let ...
because this will only work after #133852