-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
[SelectionDAG] Legalize <1 x T> vector types for atomic load #120385
base: users/jofrn/spr/main/72529270
Are you sure you want to change the base?
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
72ab88b
to
35b6ddc
Compare
35b6ddc
to
11174c5
Compare
7fa5c04
to
0dc865a
Compare
11b950d
to
ff979b4
Compare
19358e8
to
5fd5631
Compare
ff979b4
to
e3d8ddd
Compare
5fd5631
to
6444a74
Compare
e3d8ddd
to
02d1d2d
Compare
6444a74
to
28d94e9
Compare
28d94e9
to
e3f4940
Compare
8d438cf
to
c7f5fea
Compare
e3f4940
to
87b7090
Compare
c7f5fea
to
9be2b4d
Compare
0211266
to
d4f4fa8
Compare
a1143a0
to
2a1b149
Compare
d4f4fa8
to
1ee9bde
Compare
2a1b149
to
d536a40
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
ff2e168
to
6a5ac3f
Compare
d536a40
to
24d9628
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
v1i32
toi32
.Stack: