diff options
| author | bors <bors@rust-lang.org> | 2023-03-13 13:53:24 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-03-13 13:53:24 +0000 |
| commit | cf8d98b227fd3c7e50aa5a9453141c5edbf5df38 (patch) | |
| tree | 26d0368502a6b4f7b6cd975296d20c12b67caa63 /tests/codegen | |
| parent | f1b1ed7e18f1fbe5226a96626827c625985f8285 (diff) | |
| parent | e97505704e2043df46c99c3cbd0dd1ce3938c123 (diff) | |
| download | rust-cf8d98b227fd3c7e50aa5a9453141c5edbf5df38.tar.gz rust-cf8d98b227fd3c7e50aa5a9453141c5edbf5df38.zip | |
Auto merge of #108623 - scottmcm:try-different-as-slice-impl, r=the8472
Move `Option::as_slice` to an always-sound implementation This approach depends on CSE to not have any branches or selects when the guessed offset is correct -- which it always will be right now -- but to also be *sound* (just less efficient) if the layout algorithms change such that the guess is incorrect. The codegen test confirms that CSE handles this as expected, leaving the optimal codegen. cc JakobDegen #108545
Diffstat (limited to 'tests/codegen')
| -rw-r--r-- | tests/codegen/option-as-slice.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/tests/codegen/option-as-slice.rs b/tests/codegen/option-as-slice.rs index d5077dbf6cc..d735d558374 100644 --- a/tests/codegen/option-as-slice.rs +++ b/tests/codegen/option-as-slice.rs @@ -1,4 +1,4 @@ -// compile-flags: -O +// compile-flags: -O -Z randomize-layout=no // only-x86_64 #![crate_type = "lib"] @@ -12,17 +12,25 @@ use core::option::Option; // CHECK-LABEL: @u64_opt_as_slice #[no_mangle] pub fn u64_opt_as_slice(o: &Option<u64>) -> &[u64] { - // CHECK: start: // CHECK-NOT: select - // CHECK: ret + // CHECK-NOT: br + // CHECK-NOT: switch + // CHECK-NOT: icmp o.as_slice() } // CHECK-LABEL: @nonzero_u64_opt_as_slice #[no_mangle] pub fn nonzero_u64_opt_as_slice(o: &Option<NonZeroU64>) -> &[NonZeroU64] { - // CHECK: start: // CHECK-NOT: select - // CHECK: ret + // CHECK-NOT: br + // CHECK-NOT: switch + // CHECK-NOT: icmp + // CHECK: %[[NZ:.+]] = icmp ne i64 %{{.+}}, 0 + // CHECK-NEXT: zext i1 %[[NZ]] to i64 + // CHECK-NOT: select + // CHECK-NOT: br + // CHECK-NOT: switch + // CHECK-NOT: icmp o.as_slice() } |
