Skip to content

Commit

Permalink
Added test for cold_path()
Browse files Browse the repository at this point in the history
  • Loading branch information
x17jiri committed Jan 15, 2025
1 parent 0d7f30e commit 1881248
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/codegen/hint/cold_path.rs
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();
}
}

#[no_mangle]
pub fn test2(x: i32) {
match x > 0 {
true => path_a(),
false => {
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

// 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}

0 comments on commit 1881248

Please sign in to comment.