@@ -27536,8 +27536,24 @@ static SDValue scalarizeBinOpOfSplats(SDNode *N, SelectionDAG &DAG,
2753627536 if (N0.getOpcode() == ISD::BUILD_VECTOR && N0.getOpcode() == N1.getOpcode()) {
2753727537 // bo (build_vec ..undef, X, undef...), (build_vec ..undef, Y, undef...) -->
2753827538 // insert_vector_elt undef, (bo X, Y), index
27539- return DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, VT, DAG.getUNDEF(VT),
27540- ScalarBO, IndexC);
27539+
27540+ SmallVector<SDValue, 16> EltsX, EltsY;
27541+ DAG.ExtractVectorElements(Src0, EltsX);
27542+ DAG.ExtractVectorElements(Src1, EltsY);
27543+
27544+ SmallVector<SDValue, 16> EltsResult;
27545+
27546+ unsigned NonUndefElements = 0;
27547+ for (auto [X, Y] : zip(EltsX, EltsY)) {
27548+ SDValue ScalarBO = DAG.getNode(Opcode, DL, EltVT, X, Y, N->getFlags());
27549+ if (!ScalarBO.isUndef())
27550+ if (NonUndefElements++ > 1)
27551+ break;
27552+ EltsResult.push_back(ScalarBO);
27553+ }
27554+
27555+ if (NonUndefElements == 1)
27556+ return DAG.getBuildVector(VT, DL, EltsResult);
2754127557 }
2754227558
2754327559 // bo (splat X, Index), (splat Y, Index) --> splat (bo X, Y), Index
0 commit comments