Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Represent
Result<usize, Box<T>>
as ScalarPair(i64, ptr) #121668Represent
Result<usize, Box<T>>
as ScalarPair(i64, ptr) #121668Changes from 3 commits
4dabbcb
f574c65
8e40b17
5ccada6
9f55200
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am surprised that this just works, inserting
inttoptr
/ptrtoint
as necessary with only a layout change and no changes to codegen. It feels like something in codegen is a bit too permissive about adding casts whenever it needs to...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is optimized IR, so it's likely that rustc did something much more boring but LLVM optimized it to this.
Add
-C no-prepopulate-passes
in thecompile-flags
if you want to look at what cg_llvm is doing directly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, you get an
inttoptr
like that after LLVM optimizes a store+load: https://rust.godbolt.org/z/qMPWr7TzzThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Rust would actually prefer this example to be a GEP off null, like #121242, I think. Not that this PR would need to do that.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did I forget that...
Yeah, the IR we generate just spills to an alloca.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this is no longer just a
ret
instruction, this is the fewest possible instructions for scalar pair layout, since you need to pack the two separate arguments into a single return value.For real, non-noop code, the scalar pair layout is arguably slightly better, since passing the components in separate arguments means that consuming code can just use the second argument directly, instead of having to shift it down from the top 32 bits of an i64 reg.
It was kinda janky in the first place for this test to rely on the fact that integers with differing signedness don't get scalar pair layout;
Result<u32, u32>
has always gotten the same scalar pair layout (since 1.27) thatResult<i32, u32>
now gets with this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, agreed it's fine to change this test like this. The important part is that it's not branching, not
icmp
ing, notselect
ing, etc.