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

Unify Rvalue::Aggregate paths in cg_ssa #124999

Merged
merged 2 commits into from
May 13, 2024
Merged

Conversation

scottmcm
Copy link
Member

In #123840 and #123886 I added two different codepaths for Rvalue::Aggregate in cg_ssa.

This merges them into one, since raw pointers are also immediates that can be built from the immediates of their "fields".

@rustbot
Copy link
Collaborator

rustbot commented May 11, 2024

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 11, 2024
Comment on lines +768 to +736
debug_assert!(
val.is_expected_variant_for_type(self.cx, layout),
"Made wrong variant {val:?} for type {layout:?}",
);
Copy link
Member Author

Choose a reason for hiding this comment

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

Added this to help make the ICE clearer in debug, since otherwise it hit this less-helpful one:

_ => bug!("not immediate: {:?}", self),

let ty = rvalue.ty(self.mir, self.cx.tcx());
let ty = self.monomorphize(ty);
let layout = self.cx.layout_of(ty);

let field_indices = if let mir::AggregateKind::RawPtr(..) = **kind {
// `index_by_increasing_offset` gives an empty iterator for primitives
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens if we instead modify Index_by_increasing_offset to also return the fields of a raw ptr? I would expect that we'd want to consistently treat raw pointers as (actual_ptr, metadata) pairs during codegen

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I haven't audited the other 6 places this is used. I know that when I implemented AggregateKind::RawPtr originally I tried doing it via the non-OperandValue path, but that tried to project into a pointer which also didn't have the fields and thus ICEd. Maybe it'd make sense to have fat pointers at least have the two fields, if they don't? I'm not sure.

One thing about this code specifically, though, is that RawPtr always takes two "field" arguments, because from_raw_parts wants from_raw_parts(thin, ()) to work for thin pointers too. And I have to assume that we don't want thin pointers to have a unit metadata field in the Layout? So the debug assertion about the field lengths matching couldn't be done any more, though maybe that's fine and we can instead trust the MIR validator for it instead...

I think my preference here would be to leave this as-is, because even if changing index_by_increasing_offset (and possibly pointer layouts in general) is the right way forward, I think it should be its own PR.

Copy link
Member Author

@scottmcm scottmcm May 11, 2024

Choose a reason for hiding this comment

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

Well, a quick scan through the other uses of index_by_increasing_offset suggests that it's almost entirely for Aggregates, and thus we can probably tweak it directly. I've pushed a commit with that; let's see what CI thinks about it. It definitely makes the change in cg_ssa nicer, so here's hoping.

EDIT: Looks like it's happy!

@bors
Copy link
Contributor

bors commented May 12, 2024

☔ The latest upstream changes (presumably #124153) made this pull request unmergeable. Please resolve the merge conflicts.

@lcnr
Copy link
Contributor

lcnr commented May 13, 2024

nice to see that my review comment ended up being actually useful 😊 this is now involved enough for me to not be comfortable approving this myself 😅 while I think this is correct

r? compiler

@rustbot rustbot assigned nnethercote and unassigned lcnr May 13, 2024
@nnethercote
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 13, 2024

📌 Commit 99213ae has been approved by nnethercote

It is now in the queue for this repository.

@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 May 13, 2024
@bors
Copy link
Contributor

bors commented May 13, 2024

⌛ Testing commit 99213ae with merge 6be7b0c...

@bors
Copy link
Contributor

bors commented May 13, 2024

☀️ Test successful - checks-actions
Approved by: nnethercote
Pushing 6be7b0c to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 13, 2024
@bors bors merged commit 6be7b0c into rust-lang:master May 13, 2024
7 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 13, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6be7b0c): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.3% [-2.5%, -2.1%] 2
All ❌✅ (primary) - - 0

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.4% [2.4%, 2.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.2%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [0.2%, 0.2%] 1

Bootstrap: 677.638s -> 675.291s (-0.35%)
Artifact size: 315.98 MiB -> 315.98 MiB (0.00%)

@scottmcm scottmcm deleted the unify-aggregate branch May 13, 2024 17:05
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants