[clang] [llvm] Don't optimize out no-op atomics in kernel mode (PR #193562)

via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 27 04:54:35 PDT 2026


eleviant wrote:

> > possibly the frontend should be marking all atomicrmw ops as volatile if -fms-kernel is used?
> 
> If the intent of the kernel is "this memory access must be lowered to an actual asm access" then yeah it should be marked volatile.

Actually I'm quite surprised that non-volatile atomics are emitted for volatile arguments:
```
void access_via_interlocked(long volatile* addr) {
    _InterlockedAnd(addr, (long)-1); // addr is volatile but atomicrmw is not
}
```
Is this a bug? My first attempt was to fix this, emitting volatile atomic for volatile args everywhere, not just for -fms-kernel, but it breaks few existing tests. @efriedma-quic , @nikic what's your opinion on this?

https://github.com/llvm/llvm-project/pull/193562


More information about the cfe-commits mailing list