Skip to content

Commit 225ee03

Browse files
authored
[DAG] foldCONCAT_VECTORS - fold concat_vectors(v1xX insertelt(v,e,0), ...) -> build_vector(e,...) (#163420)
Extend the foldCONCAT_VECTORS BUILD_VECTOR construction to handle cases where the scalars have come from <1 x X> vector insertions Fixes #163023
1 parent 484284e commit 225ee03

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6405,8 +6405,9 @@ static SDValue foldCONCAT_VECTORS(const SDLoc &DL, EVT VT,
64056405
if (VT.isScalableVector())
64066406
return SDValue();
64076407

6408-
// A CONCAT_VECTOR with all UNDEF/BUILD_VECTOR operands can be
6409-
// simplified to one big BUILD_VECTOR.
6408+
// A CONCAT_VECTOR of scalar sources, such as UNDEF, BUILD_VECTOR and
6409+
// single-element INSERT_VECTOR_ELT operands can be simplified to one big
6410+
// BUILD_VECTOR.
64106411
// FIXME: Add support for SCALAR_TO_VECTOR as well.
64116412
EVT SVT = VT.getScalarType();
64126413
SmallVector<SDValue, 16> Elts;
@@ -6416,6 +6417,10 @@ static SDValue foldCONCAT_VECTORS(const SDLoc &DL, EVT VT,
64166417
Elts.append(OpVT.getVectorNumElements(), DAG.getUNDEF(SVT));
64176418
else if (Op.getOpcode() == ISD::BUILD_VECTOR)
64186419
Elts.append(Op->op_begin(), Op->op_end());
6420+
else if (Op.getOpcode() == ISD::INSERT_VECTOR_ELT &&
6421+
OpVT.getVectorNumElements() == 1 &&
6422+
isNullConstant(Op.getOperand(2)))
6423+
Elts.push_back(Op.getOperand(1));
64196424
else
64206425
return SDValue();
64216426
}

llvm/test/CodeGen/X86/masked_gather_scatter.ll

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4768,16 +4768,10 @@ declare void @llvm.masked.scatter.v8f32.v8p0(<8 x float>, <8 x ptr>, i32 immarg,
47684768
define <16 x i32> @pr163023(ptr %a0, <16 x i32> %a1) {
47694769
; X64-LABEL: pr163023:
47704770
; X64: # %bb.0:
4771-
; X64-NEXT: vpmovsxdq %ymm0, %zmm1
4772-
; X64-NEXT: vextracti64x4 $1, %zmm0, %ymm0
4773-
; X64-NEXT: vpmovsxdq %ymm0, %zmm0
47744771
; X64-NEXT: kxnorw %k0, %k0, %k1
4775-
; X64-NEXT: vpxor %xmm2, %xmm2, %xmm2
4776-
; X64-NEXT: vpxor %xmm3, %xmm3, %xmm3
4777-
; X64-NEXT: kxnorw %k0, %k0, %k2
4778-
; X64-NEXT: vpgatherqd (%rdi,%zmm0), %ymm3 {%k2}
4779-
; X64-NEXT: vpgatherqd (%rdi,%zmm1), %ymm2 {%k1}
4780-
; X64-NEXT: vinserti64x4 $1, %ymm3, %zmm2, %zmm0
4772+
; X64-NEXT: vpxor %xmm1, %xmm1, %xmm1
4773+
; X64-NEXT: vpgatherdd (%rdi,%zmm0), %zmm1 {%k1}
4774+
; X64-NEXT: vmovdqa64 %zmm1, %zmm0
47814775
; X64-NEXT: retq
47824776
;
47834777
; X86-LABEL: pr163023:

0 commit comments

Comments
 (0)