2025-02-08 19:45:40 -08:00
|
|
|
//@ compile-flags: -Copt-level=3
|
2016-08-31 16:02:55 -07:00
|
|
|
#![crate_type = "lib"]
|
|
|
|
#![feature(core_intrinsics)]
|
|
|
|
|
2024-07-26 15:51:46 +02:00
|
|
|
use std::intrinsics::likely;
|
2016-08-31 16:02:55 -07:00
|
|
|
|
2024-07-26 15:51:46 +02:00
|
|
|
#[inline(never)]
|
2016-08-31 16:02:55 -07:00
|
|
|
#[no_mangle]
|
2024-07-26 15:51:46 +02:00
|
|
|
pub fn path_a() {
|
|
|
|
println!("path a");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(never)]
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn path_b() {
|
|
|
|
println!("path b");
|
2016-08-31 16:02:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2024-07-26 15:51:46 +02:00
|
|
|
pub fn test_likely(x: bool) {
|
|
|
|
if likely(x) {
|
|
|
|
path_a();
|
|
|
|
} else {
|
|
|
|
path_b();
|
2016-08-31 16:02:55 -07:00
|
|
|
}
|
|
|
|
}
|
2024-07-26 15:51:46 +02:00
|
|
|
|
|
|
|
// CHECK-LABEL: @test_likely(
|
|
|
|
// CHECK: br i1 %x, label %bb2, label %bb3, !prof ![[NUM:[0-9]+]]
|
|
|
|
// CHECK: bb3:
|
|
|
|
// CHECK-NOT: cold_path
|
|
|
|
// CHECK: path_b
|
|
|
|
// CHECK: bb2:
|
|
|
|
// CHECK: path_a
|
|
|
|
// CHECK: ![[NUM]] = !{!"branch_weights", {{(!"expected", )?}}i32 2000, i32 1}
|