[llvm] e1d649a - [LowerAtomic] Clear elementwise flag when lowering atomic load (#213401)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 2 01:54:43 PDT 2026
Author: Harrison Hao
Date: 2026-08-02T16:54:39+08:00
New Revision: e1d649a644a5a18585aa7324fb35e7792314eb4f
URL: https://github.com/llvm/llvm-project/commit/e1d649a644a5a18585aa7324fb35e7792314eb4f
DIFF: https://github.com/llvm/llvm-project/commit/e1d649a644a5a18585aa7324fb35e7792314eb4f.diff
LOG: [LowerAtomic] Clear elementwise flag when lowering atomic load (#213401)
The lower atomic pass demotes atomic loads to non atomic by
calling setAtomic(NotAtomic), but left the elementwise flag untouched.
Since elementwise is only valid on atomic operations, this produced a
non-atomic elementwise load, which the verifier rejects with "non-atomic
load cannot be elementwise".
Reference: https://github.com/llvm/llvm-project/pull/204556
Added:
llvm/test/Transforms/LowerAtomic/atomic-load-store-elementwise.ll
Modified:
llvm/lib/Transforms/Scalar/LowerAtomicPass.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/LowerAtomicPass.cpp b/llvm/lib/Transforms/Scalar/LowerAtomicPass.cpp
index c93baf38e079b..297902181a00d 100644
--- a/llvm/lib/Transforms/Scalar/LowerAtomicPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerAtomicPass.cpp
@@ -28,6 +28,7 @@ static bool LowerFenceInst(FenceInst *FI) {
static bool LowerLoadInst(LoadInst *LI) {
LI->setAtomic(AtomicOrdering::NotAtomic);
+ LI->setElementwise(false);
return true;
}
diff --git a/llvm/test/Transforms/LowerAtomic/atomic-load-store-elementwise.ll b/llvm/test/Transforms/LowerAtomic/atomic-load-store-elementwise.ll
new file mode 100644
index 0000000000000..c50a679a634f0
--- /dev/null
+++ b/llvm/test/Transforms/LowerAtomic/atomic-load-store-elementwise.ll
@@ -0,0 +1,12 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt < %s -passes=lower-atomic -S | FileCheck %s
+
+define <2 x i32> @load_elementwise(ptr %p) {
+; CHECK-LABEL: define <2 x i32> @load_elementwise(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[V:%.*]] = load <2 x i32>, ptr [[P]], align 4
+; CHECK-NEXT: ret <2 x i32> [[V]]
+;
+ %v = load atomic elementwise <2 x i32>, ptr %p monotonic, align 4
+ ret <2 x i32> %v
+}
More information about the llvm-commits
mailing list