Closed
Description
The following code (godbolt):
#include <atomic>
unsigned char load(std::atomic_uchar &x) {
return x.load(std::memory_order_relaxed);
}
Compiles into:
load(std::atomic<unsigned char>&):
lb a0, 0(a0)
andi a0, a0, 255
ret
Instead of:
load(std::atomic<unsigned char>&):
lbu a0, 0(a0)
ret
Same is the case for unsigned short
and signed atomics casted to unsigned.
For unsigned int
signed load is correct because of the ABI, but when it is zero-extended, llvm fails to combine the zero-extension with the load.
Non-atomic loads correctly result in unsigned loads.