-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Likely unlikely fix #120370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Likely unlikely fix #120370
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -417,6 +417,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { | |
// These just return their argument | ||
self.copy_op(&args[0], dest)?; | ||
} | ||
sym::cold_path => { | ||
// This is a no-op. The intrinsic is just a hint to the optimizer. | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You added a fallback impl, so this should not be needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for the cranelift impl. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's intentional to avoid emitting a call to the fallback impl which is an empty function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then why do we have a fallback impl if it is not meant to be used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used by miri. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No it is not. Miri uses this implementation I attached the comment to. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #133163 cleans this up |
||
sym::raw_eq => { | ||
let result = self.raw_eq_intrinsic(&args[0], &args[1])?; | ||
self.write_scalar(result, dest)?; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
The loop took around 1250ms | ||
The loop took around 1350ms | ||
(It's fine for this number to change when you `--bless` this test.) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//@ compile-flags: -O | ||
#![crate_type = "lib"] | ||
#![feature(core_intrinsics)] | ||
|
||
use std::intrinsics::cold_path; | ||
|
||
#[no_mangle] | ||
pub fn test_cold_path(x: bool) { | ||
cold_path(); | ||
} | ||
|
||
// CHECK-LABEL: @test_cold_path( | ||
// CHECK-NOT: cold_path |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,35 @@ | ||
//@ compile-flags: -C no-prepopulate-passes -Copt-level=1 | ||
|
||
//@ compile-flags: -O | ||
#![crate_type = "lib"] | ||
#![feature(core_intrinsics)] | ||
|
||
use std::intrinsics::{likely, unlikely}; | ||
use std::intrinsics::likely; | ||
|
||
#[inline(never)] | ||
#[no_mangle] | ||
pub fn check_likely(x: i32, y: i32) -> Option<i32> { | ||
unsafe { | ||
// CHECK: call i1 @llvm.expect.i1(i1 %{{.*}}, i1 true) | ||
if likely(x == y) { None } else { Some(x + y) } | ||
} | ||
pub fn path_a() { | ||
println!("path a"); | ||
} | ||
|
||
#[inline(never)] | ||
#[no_mangle] | ||
pub fn path_b() { | ||
println!("path b"); | ||
} | ||
|
||
#[no_mangle] | ||
pub fn check_unlikely(x: i32, y: i32) -> Option<i32> { | ||
unsafe { | ||
// CHECK: call i1 @llvm.expect.i1(i1 %{{.*}}, i1 false) | ||
if unlikely(x == y) { None } else { Some(x + y) } | ||
pub fn test_likely(x: bool) { | ||
if likely(x) { | ||
path_a(); | ||
} else { | ||
path_b(); | ||
} | ||
} | ||
|
||
// 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} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//@ compile-flags: -O | ||
#![crate_type = "lib"] | ||
|
||
#[no_mangle] | ||
pub fn test_assert(x: bool) { | ||
assert!(x); | ||
} | ||
|
||
// check that assert! emits branch weights | ||
|
||
// CHECK-LABEL: @test_assert( | ||
// CHECK: br i1 %x, label %bb2, label %bb1, !prof ![[NUM:[0-9]+]] | ||
// CHECK: bb1: | ||
// CHECK: panic | ||
// CHECK: bb2: | ||
// CHECK: ret void | ||
// CHECK: ![[NUM]] = !{!"branch_weights", {{(!"expected", )?}}i32 2000, i32 1} |
Uh oh!
There was an error while loading. Please reload this page.