Skip to content

Commit fcefe95

Browse files
authored
[LegalizeTypes][AMDGPU]: Allow for scalarization of insert_subvector (#104236)
Legalization for when the inserted subvector is to be scalarized. https://godbolt.org/z/vx3joWqoh
1 parent 95daf1a commit fcefe95

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
865865
SDValue ScalarizeVecOp_UnaryOp(SDNode *N);
866866
SDValue ScalarizeVecOp_UnaryOp_StrictFP(SDNode *N);
867867
SDValue ScalarizeVecOp_CONCAT_VECTORS(SDNode *N);
868+
SDValue ScalarizeVecOp_INSERT_SUBVECTOR(SDNode *N, unsigned OpNo);
868869
SDValue ScalarizeVecOp_EXTRACT_VECTOR_ELT(SDNode *N);
869870
SDValue ScalarizeVecOp_VSELECT(SDNode *N);
870871
SDValue ScalarizeVecOp_VSETCC(SDNode *N);

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,9 @@ bool DAGTypeLegalizer::ScalarizeVectorOperand(SDNode *N, unsigned OpNo) {
765765
case ISD::CONCAT_VECTORS:
766766
Res = ScalarizeVecOp_CONCAT_VECTORS(N);
767767
break;
768+
case ISD::INSERT_SUBVECTOR:
769+
Res = ScalarizeVecOp_INSERT_SUBVECTOR(N, OpNo);
770+
break;
768771
case ISD::EXTRACT_VECTOR_ELT:
769772
Res = ScalarizeVecOp_EXTRACT_VECTOR_ELT(N);
770773
break;
@@ -882,6 +885,19 @@ SDValue DAGTypeLegalizer::ScalarizeVecOp_CONCAT_VECTORS(SDNode *N) {
882885
return DAG.getBuildVector(N->getValueType(0), SDLoc(N), Ops);
883886
}
884887

888+
/// The inserted subvector is to be scalarized - use insert vector element
889+
/// instead.
890+
SDValue DAGTypeLegalizer::ScalarizeVecOp_INSERT_SUBVECTOR(SDNode *N,
891+
unsigned OpNo) {
892+
// We should not be attempting to scalarize the containing vector
893+
assert(OpNo == 1);
894+
SDValue Elt = GetScalarizedVector(N->getOperand(1));
895+
SDValue ContainingVec = N->getOperand(0);
896+
return DAG.getNode(ISD::INSERT_VECTOR_ELT, SDLoc(N),
897+
ContainingVec.getValueType(), ContainingVec, Elt,
898+
N->getOperand(2));
899+
}
900+
885901
/// If the input is a vector that needs to be scalarized, it must be <1 x ty>,
886902
/// so just return the element, ignoring the index.
887903
SDValue DAGTypeLegalizer::ScalarizeVecOp_EXTRACT_VECTOR_ELT(SDNode *N) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 < %s | FileCheck -check-prefix=GCN %s
3+
4+
define void @scalarize_insert_subvector(ptr addrspace(3) %inptr, ptr addrspace(3) %inptr1, ptr addrspace(3) %outptr) {
5+
; GCN-LABEL: scalarize_insert_subvector:
6+
; GCN: ; %bb.0:
7+
; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
8+
; GCN-NEXT: ds_read_b64 v[4:5], v0
9+
; GCN-NEXT: s_waitcnt lgkmcnt(0)
10+
; GCN-NEXT: ds_read_b32 v5, v1 offset:4
11+
; GCN-NEXT: s_waitcnt lgkmcnt(0)
12+
; GCN-NEXT: ds_write_b64 v2, v[4:5]
13+
; GCN-NEXT: s_waitcnt lgkmcnt(0)
14+
; GCN-NEXT: s_setpc_b64 s[30:31]
15+
%load0 = load <2 x i32>, ptr addrspace(3) %inptr, align 8
16+
%load1= load <2 x i32>, ptr addrspace(3) %inptr1, align 8
17+
%shuffle0 = shufflevector <2 x i32> %load1, <2 x i32> poison, <1 x i32> <i32 1>
18+
%bitcast0 = bitcast <1 x i32> %shuffle0 to <2 x half>
19+
%bitcast1 = bitcast <2 x i32> %load0 to <4 x half>
20+
%shuffle1 = shufflevector <2 x half> %bitcast0, <2 x half> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
21+
%shuffle2 = shufflevector <4 x half> %bitcast1, <4 x half> %shuffle1, <4 x i32> <i32 0, i32 1, i32 4, i32 5>
22+
store <4 x half> %shuffle2, ptr addrspace(3) %outptr
23+
ret void
24+
}

0 commit comments

Comments
 (0)