[llvm] de63e4f - [Verifier] Reject elementwise atomicrmw with sub-byte element type (#213753)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 4 08:27:44 PDT 2026
Author: Yonah Goldberg
Date: 2026-08-04T08:27:39-07:00
New Revision: de63e4f3538ade12b5264e6e3f4682201ada16e8
URL: https://github.com/llvm/llvm-project/commit/de63e4f3538ade12b5264e6e3f4682201ada16e8
DIFF: https://github.com/llvm/llvm-project/commit/de63e4f3538ade12b5264e6e3f4682201ada16e8.diff
LOG: [Verifier] Reject elementwise atomicrmw with sub-byte element type (#213753)
In https://github.com/llvm/llvm-project/pull/208510/ I accidentally
introduced a bug where I allowed sub-byte element types with atomicrmw
elementwise (i.e. `<8 x i1>`).
The LangRef states:
```
The access type
must then be a fixed vector type whose total bit width is a power of two and
whose element type is supported by the corresponding scalar atomic instruction.
```
The second part of this sentence rejects sub-byte element types.
The fix is that elementwise atomics need to additionally call
`checkAtomicMemAccessSize` on the vector element type (they already call
it on the whole vector).
Added:
Modified:
llvm/lib/IR/Verifier.cpp
llvm/test/Assembler/invalid-atomicrmw-elementwise.ll
Removed:
################################################################################
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 0aa1ef4faebc1..1c2b716fefd7e 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -4768,6 +4768,8 @@ void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) {
auto *VecTy = dyn_cast<FixedVectorType>(ElTy);
Check(VecTy, "atomicrmw elementwise operand must have fixed vector type!",
&RMWI, ElTy);
+ if (VecTy)
+ checkAtomicMemAccessSize(VecTy->getElementType(), &RMWI);
}
if (Op == AtomicRMWInst::Xchg) {
diff --git a/llvm/test/Assembler/invalid-atomicrmw-elementwise.ll b/llvm/test/Assembler/invalid-atomicrmw-elementwise.ll
index 3c134cbb3b8c2..bfc6f104a2fc3 100644
--- a/llvm/test/Assembler/invalid-atomicrmw-elementwise.ll
+++ b/llvm/test/Assembler/invalid-atomicrmw-elementwise.ll
@@ -1,6 +1,8 @@
; RUN: split-file %s %t
; RUN: not llvm-as -disable-output %t/scalar.ll 2>&1 | FileCheck %t/scalar.ll
; RUN: not llvm-as -disable-output %t/odd-sized.ll 2>&1 | FileCheck %t/odd-sized.ll
+; RUN: not llvm-as -disable-output %t/non-byte.ll 2>&1 | FileCheck %t/non-byte.ll
+; RUN: not llvm-as -disable-output %t/non-byte-element.ll 2>&1 | FileCheck %t/non-byte-element.ll
; RUN: not llvm-as -disable-output %t/add-must-be-integer.ll 2>&1 | FileCheck %t/add-must-be-integer.ll
; RUN: not llvm-as -disable-output %t/fadd-must-be-fp.ll 2>&1 | FileCheck %t/fadd-must-be-fp.ll
; RUN: not llvm-as -disable-output %t/seq-cst.ll 2>&1 | FileCheck %t/seq-cst.ll
@@ -19,6 +21,20 @@ define <5 x i32> @bad_odd_sized_vector(ptr %p, <5 x i32> %v) {
ret <5 x i32> %old
}
+;--- non-byte.ll
+; CHECK: atomic memory access' size must be byte-sized
+define <4 x i1> @bad_non_byte(ptr %p, <4 x i1> %v) {
+ %old = atomicrmw elementwise xchg ptr %p, <4 x i1> %v monotonic, align 1
+ ret <4 x i1> %old
+}
+
+;--- non-byte-element.ll
+; CHECK: atomic memory access' size must be byte-sized
+define <8 x i1> @bad_non_byte_element(ptr %p, <8 x i1> %v) {
+ %old = atomicrmw elementwise xchg ptr %p, <8 x i1> %v monotonic, align 1
+ ret <8 x i1> %old
+}
+
;--- add-must-be-integer.ll
; CHECK: atomicrmw add operand must be an integer or fixed vector of integer type
define <4 x float> @bad_add(ptr %p, <4 x float> %v) {
More information about the llvm-commits
mailing list