[llvm] [IR][FunctionAttrs] Clarify memory effects of atomics (PR #193768)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 24 00:51:31 PDT 2026
================
@@ -1,10 +1,10 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes
; RUN: opt -passes=function-attrs -S < %s | FileCheck %s
-; Atomic load/store to local doesn't affect whether a function is
-; readnone/readonly.
+; Even though the load/store is on alloca, we can't mark the function as
+; readnone due to the synchronization effect.
----------------
nikic wrote:
Yes, this specific case is fine, but ignoring atomic accesses on allocas in general is not. I tried to make the comment clearer.
In most cases where we can optimize this, it will happen as part of SROA (which runs before FunctionAttrs). I guess there is a small optimization gap where we have an alloca that does not escape, but is accessed atomically with variable GEPs. In that case we could relax the accesses to not-atomic. Not sure whether that case is common enough to handle, but it should be a separate opt in any case.
https://github.com/llvm/llvm-project/pull/193768
More information about the llvm-commits
mailing list