-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Only generate a ptrtoint in AtomicPtr codegen when absolutely necessary #122220
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1132,9 +1132,15 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { | |
&mut self, | ||
op: rustc_codegen_ssa::common::AtomicRmwBinOp, | ||
dst: &'ll Value, | ||
src: &'ll Value, | ||
mut src: &'ll Value, | ||
order: rustc_codegen_ssa::common::AtomicOrdering, | ||
) -> &'ll Value { | ||
// The only RMW operation that LLVM supports on pointers is compare-exchange. | ||
if self.val_ty(src) == self.type_ptr() | ||
&& op != rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicXchg | ||
{ | ||
src = self.ptrtoint(src, self.type_isize()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there's a ptrtoint for the argument, doesn't there also have to be an inttoptr for the result? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hunh. It sure seems like an inttoptr should be required, but the previous implementation didn't have one either, right? I think I'm going to add the conversion back to pointer type anyway with a codegen test. |
||
} | ||
unsafe { | ||
llvm::LLVMBuildAtomicRMW( | ||
self.llbuilder, | ||
|
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.
should we report this somewhere upstream? Or at least track it with a FIXME or issue?
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.
Which operations does Rust use on pointers? To the most part these just don't make sense, at least not in a straightforward way (even something like
add
would run up against the provenance question).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 agree that compare-exchange is kind of the odd-one-out here (in that it makes sense and the other RMW ops do not).
Up to you where the check for it should live 🤷 I decided to sink the branch because otherwise we have an odd interface where we accept an enum but you better only pass one variant.
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.
The check is fine -- my comment was to answer @oli-obk's question on whether this needs to be reported upstream, and I think the answer is "no".