-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[RISCV] Inefficient code generated for byte atomicrmw xchg when the input is a constant zero #64090
Comments
@llvm/issue-subscribers-backend-risc-v |
If you |
InstCombine aggressively turns |
Do you have llc or opt command that will repro the above assembly? From https://godbolt.org/z/54r8h56cq llc generated |
|
Will generating amoswap followed by |
No. We need to write 0 to a single byte. amoswap writes 32 or 64 bits, but we don't know what value to put in the other bytes until after the read. Using amoand also writes 32 or 64 bits, but would allow to mask out the single byte that needs to be zeroed. |
ah, i see there is only amoswap.w and amoswap.d versions |
Just confirming that we do generate amoswap for 32 bits. https://godbolt.org/z/8MxMWe5aE |
One candidate approach posted as D156801 (sorry Craig, only seeing now you self-assigned this bug last night). |
llvm#64090 <llvm#64090> A forthcoming patch addresses these cases.
As noted in <llvm#64090>, it's more efficient to lower a partword 'atomicrmw xchg a, 0` to and amoand with appropriate mask. There are a range of possible ways to go about this - e.g. writing a combine based on the `llvm.riscv.masked.atomicrmw.xchg` intrinsic, or introducing a new interface to AtomicExpandPass to allow target-specific atomics conversions, or trying to lift the conversion into AtomicExpandPass itself based on querying some target hook. Ultimately I've gone with what appears to be the simplest approach - just covering this case in emitMaskedAtomicRMWIntrinsic. I perhaps should have given that hook a different name way back when it was introduced. This also handles the `atomicrmw xchg a, -1` case suggested by Craig during review. Fixes llvm#64090 Differential Revision: https://reviews.llvm.org/D156801
Similar to D156801 for RISCV. Link: rust-lang/rust#114034 Link: #64090 Reviewed By: SixWeining, xen0n Differential Revision: https://reviews.llvm.org/D159252
Noticed while working on rust-lang/rust#114034. When the replacement value is known to be zero then we should lower to an
amoand
instead of a LL/SC loop.IR
Current output
Ideal output
The text was updated successfully, but these errors were encountered: