diff options
| author | bors <bors@rust-lang.org> | 2024-07-30 03:22:27 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-07-30 03:22:27 +0000 |
| commit | 710ce90fbe5a4c801fa10e40d1f0bfdaee9e340b (patch) | |
| tree | 299d59815b99833ba5c7f821c62b13f9eaba84d7 /tests | |
| parent | dba8e2d2c2890a8b9e88cbf4855ac5711337946c (diff) | |
| parent | 4f78f9fbb05145d437540181fda9bcc83d5a53e4 (diff) | |
| download | rust-710ce90fbe5a4c801fa10e40d1f0bfdaee9e340b.tar.gz rust-710ce90fbe5a4c801fa10e40d1f0bfdaee9e340b.zip | |
Auto merge of #128250 - Amanieu:select_unpredictable, r=nikic
Add `select_unpredictable` to force LLVM to use CMOV 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 'tests')
| -rw-r--r-- | tests/codegen/intrinsics/select_unpredictable.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/codegen/intrinsics/select_unpredictable.rs b/tests/codegen/intrinsics/select_unpredictable.rs new file mode 100644 index 00000000000..2054838dd79 --- /dev/null +++ b/tests/codegen/intrinsics/select_unpredictable.rs @@ -0,0 +1,35 @@ +//@ compile-flags: -O + +#![feature(core_intrinsics)] +#![crate_type = "lib"] + +#[no_mangle] +pub fn test_int(p: bool, a: u64, b: u64) -> u64 { + // CHECK-LABEL: define{{.*}} @test_int + // CHECK: select i1 %p, i64 %a, i64 %b, !unpredictable + core::intrinsics::select_unpredictable(p, a, b) +} + +#[no_mangle] +pub fn test_pair(p: bool, a: (u64, u64), b: (u64, u64)) -> (u64, u64) { + // CHECK-LABEL: define{{.*}} @test_pair + // CHECK: select i1 %p, {{.*}}, !unpredictable + core::intrinsics::select_unpredictable(p, a, b) +} + +struct Large { + e: [u64; 100], +} + +#[no_mangle] +pub fn test_struct(p: bool, a: Large, b: Large) -> Large { + // CHECK-LABEL: define{{.*}} @test_struct + // CHECK: select i1 %p, {{.*}}, !unpredictable + core::intrinsics::select_unpredictable(p, a, b) +} + +#[no_mangle] +pub fn test_zst(p: bool, a: (), b: ()) -> () { + // CHECK-LABEL: define{{.*}} @test_zst + core::intrinsics::select_unpredictable(p, a, b) +} |
