-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reexport likely/unlikely in std::hint
- Loading branch information
Showing
5 changed files
with
225 additions
and
2 deletions.
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,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(); | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub fn test2(x: i32) { | ||
match likely(x > 0) { | ||
true => path_a(), | ||
false => path_b(), | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub fn test3(x: i8) { | ||
match likely(x < 7) { | ||
true => path_a(), | ||
_ => path_b(), | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub fn test4(x: u64) { | ||
match likely(x != 33) { | ||
false => path_a(), | ||
_ => 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 | ||
|
||
// CHECK-LABEL: @test2( | ||
// CHECK: br i1 %_2, label %bb2, label %bb3, !prof ![[NUM]] | ||
// CHECK: bb3: | ||
// CHECK: path_b | ||
// CHECK: bb2: | ||
// CHECK: path_a | ||
|
||
// CHECK-LABEL: @test3( | ||
// CHECK: br i1 %_2, label %bb2, label %bb3, !prof ![[NUM]] | ||
// CHECK: bb3: | ||
// CHECK: path_b | ||
// CHECK: bb2: | ||
// CHECK: path_a | ||
|
||
// 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(); | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub fn test2(x: i32) { | ||
match unlikely(x > 0) { | ||
true => path_a(), | ||
false => path_b(), | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub fn test3(x: i8) { | ||
match unlikely(x < 7) { | ||
true => path_a(), | ||
_ => path_b(), | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub fn test4(x: u64) { | ||
match unlikely(x != 33) { | ||
false => path_a(), | ||
_ => 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 | ||
|
||
// CHECK-LABEL: @test2( | ||
// CHECK: br i1 %_2, label %bb2, label %bb4, !prof ![[NUM]] | ||
// CHECK: bb4: | ||
// CHECK: path_b | ||
// CHECK: bb2: | ||
// CHECK: path_a | ||
|
||
// CHECK-LABEL: @test3( | ||
// CHECK: br i1 %_2, label %bb2, label %bb4, !prof ![[NUM]] | ||
// CHECK: bb4: | ||
// CHECK: path_b | ||
// CHECK: bb2: | ||
// CHECK: path_a | ||
|
||
// 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