I’ve noticed that neither gcc nor clang optimize away unused relaxed atomic loads: Compiler Explorer. I thought this would be permissible for relaxed loads specifically, since they’re not supposed to synchronize anything, and so removing them shouldn’t affect program behavior. Am I missing something that would make this optimization not allowed, or has it simply not been implemented yet?
Note that LLVM does appear to remove the load when it can prove that the atomic is never written to (gcc still doesn’t): Compiler Explorer.