diff options
| author | bors <bors@rust-lang.org> | 2024-07-27 09:34:26 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-07-27 09:34:26 +0000 |
| commit | 3942254d00bf95cd5920980f85ebea57a1e6ce2a (patch) | |
| tree | f8ec643322bc3ea8f94999c020ec3617ca3bff44 /tests | |
| parent | ad3c5a330173a4a6446c1ed90c72a3f5f9106888 (diff) | |
| parent | 2f2eb22b736f0eb364bd6c6119a3d3b90bf882ff (diff) | |
| download | rust-3942254d00bf95cd5920980f85ebea57a1e6ce2a.tar.gz rust-3942254d00bf95cd5920980f85ebea57a1e6ce2a.zip | |
Auto merge of #124905 - reitermarkus:u32-from-char-opt, r=scottmcm
Allow optimizing `u32::from::<char>`. Extracted from https://github.com/rust-lang/rust/pull/124307. This allows optimizing the panicking branch in the `escape_unicode` function, see https://rust.godbolt.org/z/61YhKrhvP.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/codegen/cast-optimized.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/codegen/cast-optimized.rs b/tests/codegen/cast-optimized.rs new file mode 100644 index 00000000000..313b2b4f0d6 --- /dev/null +++ b/tests/codegen/cast-optimized.rs @@ -0,0 +1,35 @@ +//@ compile-flags: -O -Z merge-functions=disabled +#![crate_type = "lib"] + +// This tests that LLVM can optimize based on the niches in the source or +// destination types for casts. + +// CHECK-LABEL: @u32_index +#[no_mangle] +pub fn u32_index(c: u32) -> [bool; 22] { + let mut array = [false; 22]; + + let index = 32 - c.leading_zeros(); + + // CHECK: call core::panicking::panic + array[index as usize] = true; + + array +} + +// CHECK-LABEL: @char_as_u32_index +#[no_mangle] +pub fn char_as_u32_index(c: char) -> [bool; 22] { + // CHECK: %[[B:.+]] = icmp ult i32 %c, 1114112 + // CHECK: call void @llvm.assume(i1 %[[B]]) + let c = c as u32; + + let mut array = [false; 22]; + + let index = 32 - c.leading_zeros(); + + // CHECK-NOT: call core::panicking::panic + array[index as usize] = true; + + array +} |
