Skip to content

[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

Open
wants to merge 1 commit into
base: users/jofrn/spr/main/72529270
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
SDValue ScalarizeVecRes_UnaryOpWithExtraInput(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);
Expand Down
15 changes: 15 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ void DAGTypeLegalizer::ScalarizeVectorResult(SDNode *N, unsigned ResNo) {
R = ScalarizeVecRes_UnaryOpWithExtraInput(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;
Expand Down Expand Up @@ -458,6 +461,18 @@ SDValue DAGTypeLegalizer::ScalarizeVecRes_INSERT_VECTOR_ELT(SDNode *N) {
return Op;
}

SDValue DAGTypeLegalizer::ScalarizeVecRes_ATOMIC_LOAD(AtomicSDNode *N) {
SDValue Result = DAG.getAtomicLoad(
ISD::NON_EXTLOAD, 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?");

Expand Down
121 changes: 119 additions & 2 deletions llvm/test/CodeGen/X86/atomic-load-store.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=x86_64-apple-macosx10.7.0 -verify-machineinstrs | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-apple-macosx10.7.0 -verify-machineinstrs -O0 | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-apple-macosx10.7.0 -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,CHECK3
; RUN: llc < %s -mtriple=x86_64-apple-macosx10.7.0 -verify-machineinstrs -O0 | FileCheck %s --check-prefixes=CHECK,CHECK0

define void @test1(ptr %ptr, i32 %val1) {
; CHECK-LABEL: test1:
Expand Down Expand Up @@ -28,3 +28,120 @@ 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
}

define <1 x i8> @atomic_vec1_i8(ptr %x) {
; CHECK3-LABEL: atomic_vec1_i8:
; CHECK3: ## %bb.0:
; CHECK3-NEXT: movzbl (%rdi), %eax
; CHECK3-NEXT: retq
;
; CHECK0-LABEL: atomic_vec1_i8:
; CHECK0: ## %bb.0:
; CHECK0-NEXT: movb (%rdi), %al
; CHECK0-NEXT: retq
%ret = load atomic <1 x i8>, ptr %x acquire, align 1
ret <1 x i8> %ret
}

define <1 x i16> @atomic_vec1_i16(ptr %x) {
; CHECK3-LABEL: atomic_vec1_i16:
; CHECK3: ## %bb.0:
; CHECK3-NEXT: movzwl (%rdi), %eax
; CHECK3-NEXT: retq
;
; CHECK0-LABEL: atomic_vec1_i16:
; CHECK0: ## %bb.0:
; CHECK0-NEXT: movw (%rdi), %ax
; CHECK0-NEXT: retq
%ret = load atomic <1 x i16>, ptr %x acquire, align 2
ret <1 x i16> %ret
}

define <1 x i32> @atomic_vec1_i8_zext(ptr %x) {
; CHECK3-LABEL: atomic_vec1_i8_zext:
; CHECK3: ## %bb.0:
; CHECK3-NEXT: movzbl (%rdi), %eax
; CHECK3-NEXT: movzbl %al, %eax
; CHECK3-NEXT: retq
;
; CHECK0-LABEL: atomic_vec1_i8_zext:
; CHECK0: ## %bb.0:
; CHECK0-NEXT: movb (%rdi), %al
; CHECK0-NEXT: movzbl %al, %eax
; CHECK0-NEXT: retq
%ret = load atomic <1 x i8>, ptr %x acquire, align 1
%zret = zext <1 x i8> %ret to <1 x i32>
ret <1 x i32> %zret
}

define <1 x i64> @atomic_vec1_i16_sext(ptr %x) {
; CHECK3-LABEL: atomic_vec1_i16_sext:
; CHECK3: ## %bb.0:
; CHECK3-NEXT: movzwl (%rdi), %eax
; CHECK3-NEXT: movswq %ax, %rax
; CHECK3-NEXT: retq
;
; CHECK0-LABEL: atomic_vec1_i16_sext:
; CHECK0: ## %bb.0:
; CHECK0-NEXT: movw (%rdi), %ax
; CHECK0-NEXT: movswq %ax, %rax
; CHECK0-NEXT: retq
%ret = load atomic <1 x i16>, ptr %x acquire, align 2
%sret = sext <1 x i16> %ret to <1 x i64>
ret <1 x i64> %sret
}

define <1 x ptr addrspace(270)> @atomic_vec1_ptr270(ptr %x) {
; CHECK-LABEL: atomic_vec1_ptr270:
; CHECK: ## %bb.0:
; CHECK-NEXT: movl (%rdi), %eax
; CHECK-NEXT: retq
%ret = load atomic <1 x ptr addrspace(270)>, ptr %x acquire, align 4
ret <1 x ptr addrspace(270)> %ret
}

define <1 x bfloat> @atomic_vec1_bfloat(ptr %x) {
; CHECK3-LABEL: atomic_vec1_bfloat:
; CHECK3: ## %bb.0:
; CHECK3-NEXT: movzwl (%rdi), %eax
; CHECK3-NEXT: pinsrw $0, %eax, %xmm0
; CHECK3-NEXT: retq
;
; CHECK0-LABEL: atomic_vec1_bfloat:
; CHECK0: ## %bb.0:
; CHECK0-NEXT: movw (%rdi), %cx
; CHECK0-NEXT: ## implicit-def: $eax
; CHECK0-NEXT: movw %cx, %ax
; CHECK0-NEXT: ## implicit-def: $xmm0
; CHECK0-NEXT: pinsrw $0, %eax, %xmm0
; CHECK0-NEXT: retq
%ret = load atomic <1 x bfloat>, ptr %x acquire, align 2
ret <1 x bfloat> %ret
}

define <1 x ptr> @atomic_vec1_ptr_align(ptr %x) nounwind {
; CHECK-LABEL: atomic_vec1_ptr_align:
; CHECK: ## %bb.0:
; CHECK-NEXT: movq (%rdi), %rax
; CHECK-NEXT: retq
%ret = load atomic <1 x ptr>, ptr %x acquire, align 8
ret <1 x ptr> %ret
}

define <1 x i64> @atomic_vec1_i64_align(ptr %x) nounwind {
; CHECK-LABEL: atomic_vec1_i64_align:
; CHECK: ## %bb.0:
; CHECK-NEXT: movq (%rdi), %rax
; CHECK-NEXT: retq
%ret = load atomic <1 x i64>, ptr %x acquire, align 8
ret <1 x i64> %ret
}
Loading