-
Notifications
You must be signed in to change notification settings - Fork 13.6k
atomicrmw on pointers: move integer-pointer cast hacks into backend #144192
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
base: master
Are you sure you want to change the base?
Conversation
rustbot has assigned @Mark-Simulacrum. Use |
This comment has been minimized.
This comment has been minimized.
// FIXME: LLVM does not support an atomic "add integer to pointer" operation, so | ||
// we need to instead add two pointers and hope that works out. See | ||
// <https://github.com/llvm/llvm-project/issues/120837>. | ||
bx.inttoptr(val, bx.backend_type(bx.layout_of(ty_mem))) |
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 now doing something pretty weird where this code casts the integer to pointer and then bx.atomic_rmw is going to cast it back to integer.
LLVM already expects the arguments to atomicrmw here to be a pointer and an integer. Now that the Rust intrinsic no longer artificially forces both arguments to be pointers, we should remove both this cast and the argument cast in atomic_rmw.
The only cast you need to keep is the cast of the return value of atomicrmw.
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 now doing something pretty weird where this code casts the integer to pointer and then bx.atomic_rmw is going to cast it back to integer.
Ah, fair.
LLVM already expects the arguments to atomicrmw here to be a pointer and an integer.
Ah right, it expects a pointer-to-integer and an integer (when it really should be ptr-to-ptr and integer, for RMWs on pointers).
Some changes occurred in compiler/rustc_codegen_gcc |
@antoyo, @GuillaumeGomez I took a wild guess with those GCC changes, please take a look. @bjorn3 this seems to somehow break cranelift, which is surprising since I thought |
3494e9c
to
a5a87d3
Compare
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
I took a guess at what I have to do in cranelift, I hope it makes sense. |
This comment has been minimized.
This comment has been minimized.
577b7f8
to
c8c38b3
Compare
This comment has been minimized.
This comment has been minimized.
1eb3567
to
bd0cb3c
Compare
This PR modifies cc @jieyouxu |
@@ -35,51 +35,62 @@ impl<T: ?Sized> Copy for *mut T {} | |||
impl ConstParamTy for AtomicOrdering {} | |||
|
|||
#[cfg(target_has_atomic = "8")] | |||
#[unsafe(no_mangle)] // let's make sure we actually generate a symbol to check |
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 think this test might actually have been ineffective ever since we gained that heuristic that automatically marks small functions as #[inline]
.
Conceptually, we want to have atomic operations on pointers of the form
fn atomic_add(ptr: *mut T, offset: usize, ...)
. However, LLVM does not directly support such operations (llvm/llvm-project#120837), so we have to cast theoffset
to a pointer somewhere.This PR moves that hack into the LLVM backend, so that the standard library, intrinsic, and Miri all work with the conceptual operation we actually want. Hopefully, one day LLVM will gain a way to represent these operations without integer-pointer casts, and then the hack will disappear entirely.
Cc @nikic -- this is the best we can do right now, right?
Fixes #134617