@@ -15890,12 +15890,47 @@ SDValue DAGCombiner::visitINSERT_SUBVECTOR(SDNode *N) {
1589015890 if (N1.isUndef())
1589115891 return N0;
1589215892
15893+ // For nested INSERT_SUBVECTORs, attempt to combine inner node first to allow
15894+ // us to pull BITCASTs from input to output.
15895+ if (N0.hasOneUse() && N0->getOpcode() == ISD::INSERT_SUBVECTOR)
15896+ if (SDValue NN0 = visitINSERT_SUBVECTOR(N0.getNode()))
15897+ return DAG.getNode(ISD::INSERT_SUBVECTOR, SDLoc(N), VT, NN0, N1, N2);
15898+
1589315899 // If this is an insert of an extracted vector into an undef vector, we can
1589415900 // just use the input to the extract.
1589515901 if (N0.isUndef() && N1.getOpcode() == ISD::EXTRACT_SUBVECTOR &&
1589615902 N1.getOperand(1) == N2 && N1.getOperand(0).getValueType() == VT)
1589715903 return N1.getOperand(0);
1589815904
15905+ // If we are inserting a bitcast value into an undef, with the same
15906+ // number of elements, just use the bitcast input of the extract.
15907+ // i.e. INSERT_SUBVECTOR UNDEF (BITCAST N1) N2 ->
15908+ // BITCAST (INSERT_SUBVECTOR UNDEF N1 N2)
15909+ if (N0.isUndef() && N1.getOpcode() == ISD::BITCAST &&
15910+ N1.getOperand(0).getOpcode() == ISD::EXTRACT_SUBVECTOR &&
15911+ N1.getOperand(0).getOperand(1) == N2 &&
15912+ N1.getOperand(0).getOperand(0).getValueType().getVectorNumElements() ==
15913+ VT.getVectorNumElements()) {
15914+ return DAG.getBitcast(VT, N1.getOperand(0).getOperand(0));
15915+ }
15916+
15917+ // If both N1 and N2 are bitcast values on which insert_subvector
15918+ // would makes sense, pull the bitcast through.
15919+ // i.e. INSERT_SUBVECTOR (BITCAST N0) (BITCAST N1) N2 ->
15920+ // BITCAST (INSERT_SUBVECTOR N0 N1 N2)
15921+ if (N0.getOpcode() == ISD::BITCAST && N1.getOpcode() == ISD::BITCAST) {
15922+ SDValue CN0 = N0.getOperand(0);
15923+ SDValue CN1 = N1.getOperand(0);
15924+ if (CN0.getValueType().getVectorElementType() ==
15925+ CN1.getValueType().getVectorElementType() &&
15926+ CN0.getValueType().getVectorNumElements() ==
15927+ VT.getVectorNumElements()) {
15928+ SDValue NewINSERT = DAG.getNode(ISD::INSERT_SUBVECTOR, SDLoc(N),
15929+ CN0.getValueType(), CN0, CN1, N2);
15930+ return DAG.getBitcast(VT, NewINSERT);
15931+ }
15932+ }
15933+
1589915934 // Combine INSERT_SUBVECTORs where we are inserting to the same index.
1590015935 // INSERT_SUBVECTOR( INSERT_SUBVECTOR( Vec, SubOld, Idx ), SubNew, Idx )
1590115936 // --> INSERT_SUBVECTOR( Vec, SubNew, Idx )
0 commit comments