Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce NullOp::AlignOf #88839

Merged
merged 2 commits into from
Sep 13, 2021
Merged

Introduce NullOp::AlignOf #88839

merged 2 commits into from
Sep 13, 2021

Conversation

nbdd0121
Copy link
Contributor

This PR introduces Rvalue::NullaryOp(NullOp::AlignOf, ty), which will be lowered from align_of, similar to size_of lowering to Rvalue::NullaryOp(NullOp::SizeOf, ty).

The changes are originally part of #88700 but since it's not dependent on other changes and could have performance impact on its own, it's separated into its own PR.

@rust-highfive
Copy link
Collaborator

Some changes occured to rustc_codegen_cranelift

cc @bjorn3

Some changes occurred in src/tools/clippy.

cc @rust-lang/clippy

@rust-highfive
Copy link
Collaborator

r? @nagisa

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 10, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Sep 11, 2021

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 11, 2021
@bors
Copy link
Contributor

bors commented Sep 11, 2021

⌛ Trying commit 52124553f7fb8a336b36f0de95aab8ea74f9d18b with merge 80cc2c0293bdf08aa9c0fd853e7507ce1a0272ba...

@bors
Copy link
Contributor

bors commented Sep 11, 2021

☀️ Try build successful - checks-actions
Build commit: 80cc2c0293bdf08aa9c0fd853e7507ce1a0272ba (80cc2c0293bdf08aa9c0fd853e7507ce1a0272ba)

@rust-timer
Copy link
Collaborator

Queued 80cc2c0293bdf08aa9c0fd853e7507ce1a0272ba with parent 4e880f8, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (80cc2c0293bdf08aa9c0fd853e7507ce1a0272ba): comparison url.

Summary: This benchmark run did not return any relevant changes.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 11, 2021
@nbdd0121 nbdd0121 force-pushed the alignof branch 2 times, most recently from 6ef80f9 to 14e0cef Compare September 11, 2021 21:15
@@ -2278,6 +2278,8 @@ impl BinOp {
pub enum NullOp {
/// Returns the size of a value of that type
SizeOf,
/// Returns the minimum alignment of a type
AlignOf,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call this MinAlignOf to distinguish it from the preferred alignment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that preferred alignment is never used in the library and hardly used in the compiler (in fact the only usage of preferred alignment is in cg_clif), and the name we expose min_align_of to the user is align_of, I think the name align_of/AlignOf is not ambiguous. I doubt if we'll ever add a PrefAlignOf nullary operator.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, indeed. Should we remove preferred alignment then if it isn't used anyway?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove preferred alignment then if it isn't used anyway?

Yeah it might be time to remove that intrinsic... @eddyb or do you think that will ever be useful again in the future?

Copy link
Member

@nagisa nagisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broadly LGTM, r=me with exhaustive matches back.

@@ -270,18 +270,23 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
M::box_alloc(self, &dest)?;
}

NullaryOp(mir::NullOp::SizeOf, ty) => {
NullaryOp(null_op, ty) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please match mir::NullOp::SizeOf | mir::NullOp::AlignOf here. so that the match remains properly exhaustive and will catch additional NullOp additions in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about change the _ arm below matching null_op to a NullOp::Box arm instead? This way we still get exhaustive match and is IMO cleaner.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion either way.

@@ -525,6 +511,27 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let operand = OperandRef { val: OperandValue::Immediate(val), layout: box_layout };
(bx, operand)
}

mir::Rvalue::NullaryOp(null_op, ty) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mir::Rvalue::NullaryOp(null_op, ty) => {
mir::Rvalue::NullaryOp(null_op@mir::NullOp::SizeOf | null_op@mir::NullOp::AlignOf, ty) => {

@@ -726,15 +726,20 @@ fn codegen_stmt<'tcx>(
let ptr = fx.bcx.inst_results(call)[0];
lval.write_cvalue(fx, CValue::by_val(ptr, box_layout));
}
Rvalue::NullaryOp(NullOp::SizeOf, ty) => {
Rvalue::NullaryOp(null_op, ty) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Rvalue::NullaryOp(null_op, ty) => {
Rvalue::NullaryOp(null_op@NullOp::SizeOf | null_op@NullOp::AlignOf, ty) => {

@nagisa
Copy link
Member

nagisa commented Sep 12, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Sep 12, 2021

📌 Commit cdec87c has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 12, 2021
@bors
Copy link
Contributor

bors commented Sep 12, 2021

⌛ Testing commit cdec87c with merge 96dee28...

@bors
Copy link
Contributor

bors commented Sep 13, 2021

☀️ Test successful - checks-actions
Approved by: nagisa
Pushing 96dee28 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 13, 2021
@bors bors merged commit 96dee28 into rust-lang:master Sep 13, 2021
@rustbot rustbot added this to the 1.57.0 milestone Sep 13, 2021
@nbdd0121 nbdd0121 deleted the alignof branch September 13, 2021 04:18
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (96dee28): comparison url.

Summary: This benchmark run did not return any relevant changes.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Manishearth added a commit to Manishearth/rust that referenced this pull request Sep 14, 2021
Remove implementation of `min_align_of` intrinsic

Since rust-lang#88839 `min_align_of` is lowered to AlignOf operator.
Manishearth added a commit to Manishearth/rust that referenced this pull request Sep 14, 2021
Remove implementation of `min_align_of` intrinsic

Since rust-lang#88839 `min_align_of` is lowered to AlignOf operator.
Manishearth added a commit to Manishearth/rust that referenced this pull request Sep 14, 2021
Remove implementation of `min_align_of` intrinsic

Since rust-lang#88839 `min_align_of` is lowered to AlignOf operator.
Manishearth added a commit to Manishearth/rust that referenced this pull request Sep 14, 2021
Remove implementation of `min_align_of` intrinsic

Since rust-lang#88839 `min_align_of` is lowered to AlignOf operator.
Manishearth added a commit to Manishearth/rust that referenced this pull request Sep 15, 2021
Remove implementation of `min_align_of` intrinsic

Since rust-lang#88839 `min_align_of` is lowered to AlignOf operator.
Manishearth added a commit to Manishearth/rust that referenced this pull request Sep 15, 2021
Remove implementation of `min_align_of` intrinsic

Since rust-lang#88839 `min_align_of` is lowered to AlignOf operator.
bjorn3 pushed a commit to bjorn3/rust that referenced this pull request Sep 19, 2021
Introduce NullOp::AlignOf

This PR introduces `Rvalue::NullaryOp(NullOp::AlignOf, ty)`, which will be lowered from `align_of`, similar to `size_of` lowering to `Rvalue::NullaryOp(NullOp::SizeOf, ty)`.

The changes are originally part of rust-lang#88700 but since it's not dependent on other changes and could have performance impact on its own, it's separated into its own PR.
flip1995 pushed a commit to flip1995/rust that referenced this pull request Sep 28, 2021
Introduce NullOp::AlignOf

This PR introduces `Rvalue::NullaryOp(NullOp::AlignOf, ty)`, which will be lowered from `align_of`, similar to `size_of` lowering to `Rvalue::NullaryOp(NullOp::SizeOf, ty)`.

The changes are originally part of rust-lang#88700 but since it's not dependent on other changes and could have performance impact on its own, it's separated into its own PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants