-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[SelectionDAG] Legalize <1 x T> vector types for atomic load #120385
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
Conversation
|
@llvm/pr-subscribers-llvm-selectiondag @llvm/pr-subscribers-backend-x86 Author: None (jofrn) ChangesScalarize vector of atomic load in SelectionDAG. Stack:
Full diff: https://github.com/llvm/llvm-project/pull/120385.diff 3 Files Affected:
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
index 571a710cc92a34..b81c9f87cb27d7 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
@@ -861,6 +861,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
SDValue ScalarizeVecRes_ExpOp(SDNode *N);
SDValue ScalarizeVecRes_INSERT_VECTOR_ELT(SDNode *N);
SDValue ScalarizeVecRes_LOAD(LoadSDNode *N);
+ SDValue ScalarizeVecRes_ATOMIC_LOAD(AtomicSDNode *N);
SDValue ScalarizeVecRes_SCALAR_TO_VECTOR(SDNode *N);
SDValue ScalarizeVecRes_VSELECT(SDNode *N);
SDValue ScalarizeVecRes_SELECT(SDNode *N);
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
index 107454a92e356c..c85e4ba2cfa5a7 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
@@ -60,6 +60,9 @@ void DAGTypeLegalizer::ScalarizeVectorResult(SDNode *N, unsigned ResNo) {
case ISD::FP_ROUND: R = ScalarizeVecRes_FP_ROUND(N); break;
case ISD::FPOWI: R = ScalarizeVecRes_ExpOp(N); break;
case ISD::INSERT_VECTOR_ELT: R = ScalarizeVecRes_INSERT_VECTOR_ELT(N); break;
+ case ISD::ATOMIC_LOAD:
+ R = ScalarizeVecRes_ATOMIC_LOAD(cast<AtomicSDNode>(N));
+ break;
case ISD::LOAD: R = ScalarizeVecRes_LOAD(cast<LoadSDNode>(N));break;
case ISD::SCALAR_TO_VECTOR: R = ScalarizeVecRes_SCALAR_TO_VECTOR(N); break;
case ISD::SIGN_EXTEND_INREG: R = ScalarizeVecRes_InregOp(N); break;
@@ -451,6 +454,18 @@ SDValue DAGTypeLegalizer::ScalarizeVecRes_INSERT_VECTOR_ELT(SDNode *N) {
return Op;
}
+SDValue DAGTypeLegalizer::ScalarizeVecRes_ATOMIC_LOAD(AtomicSDNode *N) {
+ SDValue Result = DAG.getAtomic(
+ ISD::ATOMIC_LOAD, SDLoc(N), N->getMemoryVT().getVectorElementType(),
+ N->getValueType(0).getVectorElementType(), N->getChain(), N->getBasePtr(),
+ N->getMemOperand());
+
+ // Legalize the chain result - switch anything that used the old chain to
+ // use the new one.
+ ReplaceValueWith(SDValue(N, 1), Result.getValue(1));
+ return Result;
+}
+
SDValue DAGTypeLegalizer::ScalarizeVecRes_LOAD(LoadSDNode *N) {
assert(N->isUnindexed() && "Indexed vector load?");
diff --git a/llvm/test/CodeGen/X86/atomic-load-store.ll b/llvm/test/CodeGen/X86/atomic-load-store.ll
index 5bce4401f7bdb0..9cac8167542d8b 100644
--- a/llvm/test/CodeGen/X86/atomic-load-store.ll
+++ b/llvm/test/CodeGen/X86/atomic-load-store.ll
@@ -28,3 +28,12 @@ define i32 @test3(ptr %ptr) {
%val = load atomic i32, ptr %ptr seq_cst, align 4
ret i32 %val
}
+
+define <1 x i32> @atomic_vec1_i32(ptr %x) {
+; CHECK-LABEL: atomic_vec1_i32:
+; CHECK: ## %bb.0:
+; CHECK-NEXT: movl (%rdi), %eax
+; CHECK-NEXT: retq
+ %ret = load atomic <1 x i32>, ptr %x acquire, align 4
+ ret <1 x i32> %ret
+}
|
452731d to
e294f9f
Compare
b28c988 to
b649f99
Compare
e294f9f to
7263545
Compare
b649f99 to
7d979a9
Compare
5a3a12d to
66eca4b
Compare
|
Running crashes with: |
At this PR, this is the expectation. A later PR needs to handle the other vector legalization cases |
66eca4b to
4d3fcb3
Compare
bd31cd4 to
4282e9f
Compare
| ; CHECK0-NEXT: ## implicit-def: $xmm0 | ||
| ; CHECK0-NEXT: pinsrw $0, %eax, %xmm0 | ||
| ; CHECK0-NEXT: retq | ||
| %ret = load atomic <1 x bfloat>, ptr %x acquire, align 4 |
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.
Overaligned
| ; CHECK0-NEXT: movw (%rdi), %ax | ||
| ; CHECK0-NEXT: movswq %ax, %rax | ||
| ; CHECK0-NEXT: retq | ||
| %ret = load atomic <1 x i16>, ptr %x acquire, align 4 |
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.
Over aligned (but doesn't really matter)
4d3fcb3 to
4d0be71
Compare
Well, it also doesn't work after the rest of the series. As a general comment, I find it difficult to review a series of PRs where the intermediate state between them is broken, and without any clear indication as to what is and isn't supposed to work after each PR. If this set of changes is going to remain split up into multiple PRs, the descriptions need to make it clear what's the expected state after each one, so I don't need to guess as to which of the PRs to leave a comment like that on... |
4d0be71 to
601c009
Compare
4d8ce80 to
e32bf02
Compare
The tests posted in the review work from that point on, except for when the atomics are lowered to calls in #120387 ; these have always worked. I'm posting another review to handle more cases. |
e32bf02 to
b6db331
Compare
601c009 to
3796cf7
Compare
5189e84 to
e7805ff
Compare
e7805ff to
2d7f7dc
Compare
2d7f7dc to
1e2a179
Compare
2b396ee to
46f762e
Compare
1e2a179 to
08e39f2
Compare
46f762e to
610e2d3
Compare
c476a24 to
f5cd42b
Compare
dc60764 to
dcdea9a
Compare
fd8afbf to
30182fb
Compare
320dcaa to
d56be40
Compare
2ac0180 to
6b14da3
Compare
d56be40 to
fe871e7
Compare
8671aa6 to
192b17c
Compare
192b17c to
85e5dc5
Compare
`load atomic <1 x T>` is not valid. This change legalizes vector types of atomic load via scalarization in SelectionDAG so that it can, for example, translate from `v1i32` to `i32`. commit-id:5c36cc8c
85e5dc5 to
6660b3f
Compare
load atomic <1 x T>is not valid. This change legalizesvector types of atomic load via scalarization in SelectionDAG
so that it can, for example, translate from
v1i32toi32.Stack: