Repository navigation
add c-variadic support for x87_f80 - #166510
folkertdev wants to merge 5 commits into
Conversation
| // X86_64-NEXT: mov rcx, qword ptr [rax] | ||
| // X86_64-NEXT: movzx edx, byte ptr [rax + 8] | ||
| // X86_64-NEXT: movzx eax, byte ptr [rax + 9] |
There was a problem hiding this comment.
This is a 10-byte load which is worse assembly than a x87_fp80 load. Totally acceptable, certainly for now.
|
r? beetrees |
|
|
There was a problem hiding this comment.
This PR currently results in llvm_type being called on a Rust aggregate (x87_f80) and then the resulting LLVM aggregate being loaded, both of which should be avoided. One solution that would work in this particular case is to substitute cx.type_x87_f80() when layout.is_x87_f80() and let the llvm_value_to_intrinsicresult call at the bottom of codegen_rustc_intrinsic_call store it to the result place. This would work in this particular scenario (and would be fine for this PR), but won't work for other BackendRepr::Memory aggregates like Complex<x87_f80> that can't be represented as a LLVM primitive. The more long-term solution would be to pass result_place to emit_va_arg and directly memcpy the result into it.
Could you also add an codegen-llvm test for the IR emitted by next_arg::<x87_f80>()? Since this is the first Rust aggregate type to have va_arg support it would be good to have a test for what LLVM IR we emit.
|
Reminder, once the PR becomes ready for a review, use |
8bbf69e to
9336909
Compare
This comment has been minimized.
This comment has been minimized.
| // The backend_repr of x87_f80 is not a scalar, so it needs special-casing. | ||
| if result_layout.is_x87_f80(self) { | ||
| break 'blk emit_va_arg(self, args[0], result_layout); | ||
| } | ||
|
|
||
| let BackendRepr::Scalar(scalar) = result_layout.backend_repr else { | ||
| bug!("the va_arg intrinsic does not support non-scalar types") | ||
| }; |
There was a problem hiding this comment.
Rather than use a break 'blk, maybe something like:
match result_layout.backend_repr {
BackendRepr::Scalar(scalar) => {
match scalar.primitive() {
...
}
}
_ if result_layout.is_x87_f80(self) => {}
_ => bug!("the va_arg intrinsic does not support non-scalar type {result_layout:?}")
}There was a problem hiding this comment.
Bumps the indentation by 2 more levels
There was a problem hiding this comment.
Splitting it out into a function is also a bit awkward with all the bug!s
There was a problem hiding this comment.
How about keeping the break 'blk but still have only a single callsite for emit_va_arg(self, args[0], result_layout)? Something like
'blk: {
if result_layout.is_x87_f80(self) {
break 'blk;
}
let BackendRepr::Scalar(scalar) = result_layout.backend_repr else {
bug!("the va_arg intrinsic does not support non-scalar types")
};
...
}
emit_va_arg(self, args[0], result_layout)That would only increase the indentation by one level and would make the control flow easier to follow IMO.
There was a problem hiding this comment.
Using a if let BackendRepr::Scalar(scalar) = result_layout.backend_repr instead of a match would also only increase the indentation by a single level, so that could also be an option.
There was a problem hiding this comment.
sure I've mode the block around.
9336909 to
d6027f8
Compare
| // The backend_repr of x87_f80 is not a scalar, so it needs special-casing. | ||
| if result_layout.is_x87_f80(self) { | ||
| break 'blk emit_va_arg(self, args[0], result_layout); | ||
| } | ||
|
|
||
| let BackendRepr::Scalar(scalar) = result_layout.backend_repr else { | ||
| bug!("the va_arg intrinsic does not support non-scalar types") | ||
| }; |
There was a problem hiding this comment.
Splitting it out into a function is also a bit awkward with all the bug!s
This comment has been minimized.
This comment has been minimized.
d6027f8 to
1cd12c4
Compare
I guess things got renamed and there were some editing mishaps.
1cd12c4 to
5300ab3
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
tracking issue: #163982
The default paths already have the right behavior. Validated with abi-cafe.