forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#99174 - scottmcm:reoptimize-layout-array, r=j…
…oshtriplett Reoptimize layout array This way it's one check instead of two, so hopefully (cc rust-lang#99117) it'll be simpler for rustc perf too 🤞 Quick demonstration: ```rust pub fn demo(n: usize) -> Option<Layout> { Layout::array::<i32>(n).ok() } ``` Nightly: <https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=e97bf33508aa03f38968101cdeb5322d> ```nasm mov rax, rdi mov ecx, 4 mul rcx seto cl movabs rdx, 9223372036854775805 xor esi, esi cmp rax, rdx setb sil shl rsi, 2 xor edx, edx test cl, cl cmove rdx, rsi ret ``` This PR (note no `mul`, in addition to being much shorter): ```nasm xor edx, edx lea rax, [4*rcx] shr rcx, 61 sete dl shl rdx, 2 ret ``` This is built atop `@CAD97` 's rust-lang#99136; the new changes are cb8aba66ef6a0e17f08a0574e4820653e31b45a0. I added a bunch more tests for `Layout::from_size_align` and `Layout::array` too.
- Loading branch information
Showing
4 changed files
with
115 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// compile-flags: -O | ||
// only-x86_64 | ||
// ignore-debug: the debug assertions get in the way | ||
|
||
#![crate_type = "lib"] | ||
|
||
use std::alloc::Layout; | ||
|
||
type RGB48 = [u16; 3]; | ||
|
||
// CHECK-LABEL: @layout_array_rgb48 | ||
#[no_mangle] | ||
pub fn layout_array_rgb48(n: usize) -> Layout { | ||
// CHECK-NOT: llvm.umul.with.overflow.i64 | ||
// CHECK: icmp ugt i64 %n, 1537228672809129301 | ||
// CHECK-NOT: llvm.umul.with.overflow.i64 | ||
// CHECK: mul nuw nsw i64 %n, 6 | ||
// CHECK-NOT: llvm.umul.with.overflow.i64 | ||
Layout::array::<RGB48>(n).unwrap() | ||
} | ||
|
||
// CHECK-LABEL: @layout_array_i32 | ||
#[no_mangle] | ||
pub fn layout_array_i32(n: usize) -> Layout { | ||
// CHECK-NOT: llvm.umul.with.overflow.i64 | ||
// CHECK: icmp ugt i64 %n, 2305843009213693951 | ||
// CHECK-NOT: llvm.umul.with.overflow.i64 | ||
// CHECK: shl nuw nsw i64 %n, 2 | ||
// CHECK-NOT: llvm.umul.with.overflow.i64 | ||
Layout::array::<i32>(n).unwrap() | ||
} |