Skip to content

Commit 1881248

Browse files
committed
Added test for cold_path()
1 parent 0d7f30e commit 1881248

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/codegen/hint/cold_path.rs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//@ compile-flags: -O
2+
#![crate_type = "lib"]
3+
#![feature(cold_path)]
4+
5+
use std::hint::cold_path;
6+
7+
#[inline(never)]
8+
#[no_mangle]
9+
pub fn path_a() {
10+
println!("path a");
11+
}
12+
13+
#[inline(never)]
14+
#[no_mangle]
15+
pub fn path_b() {
16+
println!("path b");
17+
}
18+
19+
#[no_mangle]
20+
pub fn test1(x: bool) {
21+
if x {
22+
path_a();
23+
} else {
24+
cold_path();
25+
path_b();
26+
}
27+
}
28+
29+
#[no_mangle]
30+
pub fn test2(x: i32) {
31+
match x > 0 {
32+
true => path_a(),
33+
false => {
34+
cold_path();
35+
path_b()
36+
}
37+
}
38+
}
39+
40+
// CHECK-LABEL: @test1(
41+
// CHECK: br i1 %x, label %bb1, label %bb2, !prof ![[NUM:[0-9]+]]
42+
// CHECK: bb2:
43+
// CHECK: path_b
44+
// CHECK: bb1:
45+
// CHECK: path_a
46+
47+
// CHECK-LABEL: @test2(
48+
// CHECK: br i1 %_2, label %bb2, label %bb1, !prof ![[NUM]]
49+
// CHECK: bb1:
50+
// CHECK: path_b
51+
// CHECK: bb2:
52+
// CHECK: path_a
53+
54+
// CHECK: ![[NUM]] = !{!"branch_weights", {{(!"expected", )?}}i32 2000, i32 1}

0 commit comments

Comments
 (0)