about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src/check/intrinsic.rs
diff options
context:
space:
mode:
authorAmanieu d'Antras <amanieu@gmail.com>2024-07-26 19:36:21 +0100
committerAmanieu d'Antras <amanieu@gmail.com>2024-07-28 17:24:57 +0100
commit4f78f9fbb05145d437540181fda9bcc83d5a53e4 (patch)
tree0d7f49f2f98393f8afcf6d2342b3bacc433a0aca /compiler/rustc_hir_analysis/src/check/intrinsic.rs
parent355efacf0d430331c962a38af39049b76bb6266b (diff)
downloadrust-4f78f9fbb05145d437540181fda9bcc83d5a53e4.tar.gz
rust-4f78f9fbb05145d437540181fda9bcc83d5a53e4.zip
Force LLVM to use CMOV for binary search
Since https://reviews.llvm.org/D118118, LLVM will no longer turn CMOVs
into branches if it comes from a `select` marked with an `unpredictable`
metadata attribute.

This PR introduces `core::intrinsics::select_unpredictable` which emits
such a `select` and uses it in the implementation of `binary_search_by`.
Diffstat (limited to 'compiler/rustc_hir_analysis/src/check/intrinsic.rs')
-rw-r--r--compiler/rustc_hir_analysis/src/check/intrinsic.rs2
1 files changed, 2 insertions, 0 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs
index 6282499883b..dfe6a2675c3 100644
--- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs
+++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs
@@ -119,6 +119,7 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -
         | sym::type_id
         | sym::likely
         | sym::unlikely
+        | sym::select_unpredictable
         | sym::ptr_guaranteed_cmp
         | sym::minnumf16
         | sym::minnumf32
@@ -487,6 +488,7 @@ pub fn check_intrinsic_type(
             sym::assume => (0, 0, vec![tcx.types.bool], tcx.types.unit),
             sym::likely => (0, 0, vec![tcx.types.bool], tcx.types.bool),
             sym::unlikely => (0, 0, vec![tcx.types.bool], tcx.types.bool),
+            sym::select_unpredictable => (1, 0, vec![tcx.types.bool, param(0), param(0)], param(0)),
 
             sym::read_via_copy => (1, 0, vec![Ty::new_imm_ptr(tcx, param(0))], param(0)),
             sym::write_via_move => {