@@ -27527,8 +27527,24 @@ static SDValue scalarizeBinOpOfSplats(SDNode *N, SelectionDAG &DAG,
2752727527 if (N0.getOpcode() == ISD::BUILD_VECTOR && N0.getOpcode() == N1.getOpcode()) {
2752827528 // bo (build_vec ..undef, X, undef...), (build_vec ..undef, Y, undef...) -->
2752927529 // insert_vector_elt undef, (bo X, Y), index
27530- return DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, VT, DAG.getUNDEF(VT),
27531- ScalarBO, IndexC);
27530+
27531+ SmallVector<SDValue, 16> EltsX, EltsY;
27532+ DAG.ExtractVectorElements(Src0, EltsX);
27533+ DAG.ExtractVectorElements(Src1, EltsY);
27534+
27535+ SmallVector<SDValue, 16> EltsResult;
27536+
27537+ unsigned NonUndefElements = 0;
27538+ for (auto [X, Y] : zip(EltsX, EltsY)) {
27539+ SDValue ScalarBO = DAG.getNode(Opcode, DL, EltVT, X, Y, N->getFlags());
27540+ if (!ScalarBO.isUndef())
27541+ if (NonUndefElements++ > 1)
27542+ break;
27543+ EltsResult.push_back(ScalarBO);
27544+ }
27545+
27546+ if (NonUndefElements == 1)
27547+ return DAG.getBuildVector(VT, DL, EltsResult);
2753227548 }
2753327549
2753427550 // bo (splat X, Index), (splat Y, Index) --> splat (bo X, Y), Index
0 commit comments