Simplify align_of_val::<[T]>(…) → align_of::<T>()#144566
Simplify align_of_val::<[T]>(…) → align_of::<T>()#144566bors merged 3 commits intorust-lang:masterfrom
align_of_val::<[T]>(…) → align_of::<T>()#144566Conversation
|
r? @davidtwco rustbot has assigned @davidtwco. Use |
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
| pub fn of_val_slice<T>(slice: &[T]) -> usize { | ||
| // CHECK-LABEL: fn of_val_slice(_1: &[T]) | ||
| // CHECK: _0 = AlignOf(T); | ||
| unsafe { core::intrinsics::align_of_val(slice) } | ||
| } |
There was a problem hiding this comment.
Since you're explicitly mentioning this running after inlining, maybe change it to
| pub fn of_val_slice<T>(slice: &[T]) -> usize { | |
| // CHECK-LABEL: fn of_val_slice(_1: &[T]) | |
| // CHECK: _0 = AlignOf(T); | |
| unsafe { core::intrinsics::align_of_val(slice) } | |
| } | |
| pub fn of_val_slice<T>(slice: &[T]) -> usize { | |
| // CHECK-LABEL: fn of_val_slice(_1: &[T]) | |
| // CHECK: _0 = AlignOf(T); | |
| something_inlined(slice) | |
| } | |
| #[inline(always)] | |
| fn something_inlined<T: ?Sized>(val: &T) -> usize { | |
| unsafe { core::intrinsics::align_of_val(slice) } | |
| } |
or use the mem wrapper
There was a problem hiding this comment.
Hmm, that wouldn't work with test-mir-pass -- this folder is more unit testy, usually.
I guess I can just bring over the test from https://github.com/rust-lang/rust/pull/144572/files#diff-9e6b893e458a80c489851369ec09247ad188228d94c4c92d3ba28fea1702fdc8 though.
There was a problem hiding this comment.
Just merging is fine with me, I was mostly wondering why it wasn't this way. r=me at your discretion what you think is best
|
unlikely to have a perf effect outside of microbenchmarks, but it may also unlock other opts, so let's perf it to decide whether to rollup or not @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Simplify `align_of_val::<[T]>(…)` → `align_of::<T>()`
| } | ||
| scope 23 (inlined Layout::align) { | ||
| scope 24 (inlined std::ptr::Alignment::as_usize) { | ||
| let mut _10: u32; |
There was a problem hiding this comment.
annot: this u32 is why the test needs to be split by bit width.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (045ae4f): comparison URL. Overall result: ❌ regressions - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResults (secondary 1.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 467.912s -> 468.532s (0.13%) |
|
Probably llvm opt noise @bors r+ rollup |
Rollup of 6 pull requests Successful merges: - #144560 (coverage: Treat `#[automatically_derived]` as `#[coverage(off)]`) - #144566 (Simplify `align_of_val::<[T]>(…)` → `align_of::<T>()`) - #144587 (expand: Micro-optimize prelude injection) - #144589 (Account for `.yield` in illegal postfix operator message) - #144615 (Make resolve_fn_signature responsible for its own rib.) - #144634 (Fix typo in `DropGuard` doc) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #144566 - scottmcm:align-of-slice, r=oli-obk Simplify `align_of_val::<[T]>(…)` → `align_of::<T>()` I spotted this while working on the inliner (#144561). In particular, if [`Layout::for_value`](https://doc.rust-lang.org/std/alloc/struct.Layout.html#method.for_value) inlines, then it can be pretty easy to end up with an `align_of_val::<[T]>` today (demo: <https://rust.godbolt.org/z/Tesnscj4a>) where we can save at least a block, if not more, by using the version that's an rvalue and not a call.
I spotted this while working on the inliner (#144561). In particular, if
Layout::for_valueinlines, then it can be pretty easy to end up with analign_of_val::<[T]>today (demo: https://rust.godbolt.org/z/Tesnscj4a) where we can save at least a block, if not more, by using the version that's an rvalue and not a call.