-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IR: Allow vector type in atomic load and store #117625
Conversation
@llvm/pr-subscribers-llvm-ir Author: None (jofrn) ChangesVector types on atomics are assumed to be invalid by the verifier. However, this type can be valid if it is lowered by codegen. Full diff: https://github.com/llvm/llvm-project/pull/117625.diff 2 Files Affected:
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 55de486e90e190..83eb1ef0c229a7 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -4255,9 +4255,9 @@ void Verifier::visitLoadInst(LoadInst &LI) {
Check(LI.getOrdering() != AtomicOrdering::Release &&
LI.getOrdering() != AtomicOrdering::AcquireRelease,
"Load cannot have Release ordering", &LI);
- Check(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy(),
- "atomic load operand must have integer, pointer, or floating point "
- "type!",
+ Check(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy() || ElTy->isVectorTy(),
+ "atomic load operand must have integer, pointer, floating point, "
+ "or vector type!",
ElTy, &LI);
checkAtomicMemAccessSize(ElTy, &LI);
} else {
@@ -4281,9 +4281,9 @@ void Verifier::visitStoreInst(StoreInst &SI) {
Check(SI.getOrdering() != AtomicOrdering::Acquire &&
SI.getOrdering() != AtomicOrdering::AcquireRelease,
"Store cannot have Acquire ordering", &SI);
- Check(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy(),
- "atomic store operand must have integer, pointer, or floating point "
- "type!",
+ Check(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy() || ElTy->isVectorTy(),
+ "atomic store operand must have integer, pointer, floating point, "
+ "or vector type!",
ElTy, &SI);
checkAtomicMemAccessSize(ElTy, &SI);
} else {
diff --git a/llvm/test/Verifier/atomics.ll b/llvm/test/Verifier/atomics.ll
index f835b98b243456..17bf5a0528d738 100644
--- a/llvm/test/Verifier/atomics.ll
+++ b/llvm/test/Verifier/atomics.ll
@@ -1,14 +1,15 @@
; RUN: not opt -passes=verify < %s 2>&1 | FileCheck %s
+; CHECK: atomic store operand must have integer, pointer, floating point, or vector type!
+; CHECK: atomic load operand must have integer, pointer, floating point, or vector type!
-; CHECK: atomic store operand must have integer, pointer, or floating point type!
-; CHECK: atomic load operand must have integer, pointer, or floating point type!
+%ty = type { i32 };
-define void @foo(ptr %P, <1 x i64> %v) {
- store atomic <1 x i64> %v, ptr %P unordered, align 8
+define void @foo(ptr %P, %ty %v) {
+ store atomic %ty %v, ptr %P unordered, align 8
ret void
}
-define <1 x i64> @bar(ptr %P) {
- %v = load atomic <1 x i64>, ptr %P unordered, align 8
- ret <1 x i64> %v
+define %ty @bar(ptr %P) {
+ %v = load atomic %ty, ptr %P unordered, align 8
+ ret %ty %v
}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
4962b17
to
af5cac7
Compare
#117189 requires this change. |
Vector types on atomics are assumed to be invalid by the verifier. However, this type can be valid if it is lowered by codegen.
af5cac7
to
9b0a33b
Compare
I'm a little confused by the steps being taken here. Can we have this fallback via cast to integer by default on all platforms, at the same time as making it legal? (That's how floats were handled, e.g.). We shouldn't have this work only on some platforms, but not others. |
We can do that. However, the Verifier would still mark it as invalid. The subsequent PR only lowers for X86 ; this PR allows vector types without disabling verifier checks, which is required before enabling for any platform. |
I don't understand why do this in multiple steps? Allow vectors in the verifier and update all of the existing implementations of shouldCastAtomic{Load,Story}InIR to cast vectors at the same time? |
Verifier checks can be disabled with |
Disagree, split the IR verifier change from the codegen pieces.
There's a ton of IR that will not work on all platforms with varying failure modes, this case isn't special (e.g. 128-bit atomics) |
I agree with @jyknight that this needs to come with support for all targets, not just X86. Preferably implemented in a way that does not require defining a hook in every single backend.
We should always aspire to make generic IR constructs work target-independently. If we have fallen short of that in some area, that's not an excuse to repeat the mistake. |
Currently, IR having load/store atomic with a vector type is invalid. If you disable the verifier and provide invalid IR to LLVM, what happens next may be arbitrary -- nobody should be depending on that. So, I would strongly suggest that the first change be to unconditionally cast the vector to integers -- both in the base class TargetLoweringBase::shouldCastAtomicLoadInIR/shouldCastAtomicStoreInIR and in all the overrides (looks like 3 of those: NVPTX, AMDGPU, SystemZ). Then, you can make separate follow-up changes for each target to opt out of the cast when possible. |
Yes, the codegen patch should implement the generic path for all targets. But in terms of patch splitting, that shouldn't be in this PR
There are limits to what is practically implementable for operations that support arbitrary types. ppc_f128, x86_fp80, scalable vectors, and arbitrarily sized atomics are never going to be universally supported.
We really should get rid of these hooks. There's no reason this can't just be handled by ordinary type legalization |
I somewhat disagree -- I do think it makes more sense to do this in one commit -- especially since the necessary codegen changes are small. However, that's only a weak preference; if the author wishes to do this in a series of PRs, that's also OK as long they'll all land together.
Sounds great, but that certainly seems like a separable change. Since these hooks are how it's done today for floats, I don't see a reason to (initially) do something different for vectors. |
The change from my end only needs X86 support. If we can get this PR and the next PR in (whether they are together or not), then the internal test will pass. Some of the backend implementations are already implemented too, so we might as well enable it separately. |
That is insufficient. The functionality (of passing a vector type to load/store atomic) needs to work for all targets, even if your use-case doesn't require it. |
I switched AMDGPU to use the DAG legalization in 82bb253. I thought I switched X86 over but that seems to not have landed
There's no plus to only doing x86. Just handle in the default implementation of the hook |
Regardless of using the hook, backends are still able to implement atomic load/store of vector, so I do not see why we cannot enable the verifier change separately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can land the verifier change separately, but only after a non-x86-specific patch for backend support is available as well.
I'm a little confused as to which PRs are intended to be reviewed now. Is it only the "follow-up" series of 4 PRs you've linked to? Or are some/all of the other 3 PRs you've sent still active? |
Vector types on atomics are assumed to be invalid by the verifier. However, this type can be valid if it is lowered by codegen.