Have the alignment intrinsics return ptr::Alignment directly#152641
Have the alignment intrinsics return ptr::Alignment directly#152641scottmcm wants to merge 2 commits intorust-lang:mainfrom
ptr::Alignment directly#152641Conversation
| bb0: { | ||
| + _2 = copy _1 as *const () (PtrToPtr); | ||
| + _3 = copy _2 as usize (Transmute); | ||
| + _4 = Sub(const <u32 as std::mem::SizedTypeProperties>::ALIGN, const 1_usize); |
There was a problem hiding this comment.
We didn't have a test for the alignment checks, it seems, so the first commit adds one.
This comment has been minimized.
This comment has been minimized.
864bde0 to
aa59f29
Compare
| // CHECK: (inlined <Box<[T]> as Drop>::drop) | ||
| // CHECK: [[SIZE:_.+]] = std::intrinsics::size_of_val::<[T]> | ||
| // CHECK: [[ALIGN:_.+]] = const <T as std::mem::SizedTypeProperties>::ALIGN; | ||
| // CHECK: [[B:_.+]] = copy [[ALIGN]] as std::ptr::Alignment (Transmute); |
There was a problem hiding this comment.
This transmute no longer being needed is perhaps the clearest demo of this PR.
This comment has been minimized.
This comment has been minimized.
aa59f29 to
5c5e512
Compare
This comment has been minimized.
This comment has been minimized.
5c5e512 to
c071e30
Compare
This comment has been minimized.
This comment has been minimized.
c071e30 to
22ff442
Compare
|
I don't think anything in here should be more expensive, but in case... |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Have the alignment intrinsics return `ptr::Alignment` directly
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (7121e2d): comparison URL. Overall result: ❌✅ regressions and improvements - 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)Results (primary -3.9%, secondary 2.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 11.9%, secondary -1.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.3%, secondary -0.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 485.129s -> 482.811s (-0.48%) |
|
Some changes occurred in compiler/rustc_codegen_gcc Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt This PR modifies cc @jieyouxu Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter |
The magnitude is indeed surprising, but squinting at the query execution changes, I do see that there are two more I'd build the benchmark before and after and |
|
IIUC, this PR does two things:
Do you have an idea which changes causes the perf improvements? |
TBH I hadn't been planning to go quite as far in one PR, but things ended up more conflated than I'd originally expected because of things like the I guess I could try adding |
|
☔ The latest upstream changes (presumably #148190) made this pull request unmergeable. Please resolve the merge conflicts. |

Follow-up to #152605
Notably, a common case of
align_of_valis to put it inLayoutfor allocator calls, so might as well have it just be anAlignmentalready to avoid the extra transmute.No changes to
rustc_const_evalbecause that's already writing aScalarinto a place, which does what we need sinceptr::Alignmentisrepr(transparent)to arepr(usize).