about summary refs log tree commit diff
path: root/tests/codegen/hint/cold_path.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-01-20 20:41:33 +0000
committerbors <bors@rust-lang.org>2025-01-20 20:41:33 +0000
commitf3d1d47fd84dfcf7f513be1dbad356e74c8f3b2b (patch)
tree3bf9ce3cf46983346a1d829e80873555105cd58e /tests/codegen/hint/cold_path.rs
parent9f4d9dc102fee5c1fe8adce2c4a58254cae510f4 (diff)
parent67b609a91958f344d71c99504808e77726af13e2 (diff)
Auto merge of #135789 - matthiaskrgr:rollup-4cvw8s4, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #133695 (Reexport likely/unlikely in std::hint)
 - #135330 (Respect --sysroot for rustc -vV and -Cpasses=list)
 - #135333 (Partial progress on #132735: Replace extern "rust-intrinsic" with #[rustc_intrinsic] across the codebase)
 - #135741 (Recognise new IPv6 documentation range from IETF RFC 9637)
 - #135770 (Update contributing docs for submodule/subtree changes)
 - #135775 (Subtree update of `rust-analyzer`)
 - #135776 (Subtree sync for rustc_codegen_cranelift)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'tests/codegen/hint/cold_path.rs')
-rw-r--r--tests/codegen/hint/cold_path.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/codegen/hint/cold_path.rs b/tests/codegen/hint/cold_path.rs
new file mode 100644
index 00000000000..dac72073f85
--- /dev/null
+++ b/tests/codegen/hint/cold_path.rs
@@ -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}