Skip to content

Commit 0fd42cf

Browse files
committed
Don't bother counting the undefs
It folds to undef or a constant and seems to have the best result anyway rather than overdefining by splatting the variable value.
1 parent 6679429 commit 0fd42cf

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

Diff for: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

+10-21
Original file line numberDiff line numberDiff line change
@@ -27517,36 +27517,25 @@ static SDValue scalarizeBinOpOfSplats(SDNode *N, SelectionDAG &DAG,
2751727517
if ((Opcode == ISD::MULHS || Opcode == ISD::MULHU) && !TLI.isTypeLegal(EltVT))
2751827518
return SDValue();
2751927519

27520-
SDValue IndexC = DAG.getVectorIdxConstant(Index0, DL);
27521-
SDValue X = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Src0, IndexC);
27522-
SDValue Y = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Src1, IndexC);
27523-
SDValue ScalarBO = DAG.getNode(Opcode, DL, EltVT, X, Y, N->getFlags());
27524-
2752527520
// If all lanes but 1 are undefined, no need to splat the scalar result.
2752627521
// TODO: Keep track of undefs and use that info in the general case.
2752727522
if (N0.getOpcode() == ISD::BUILD_VECTOR && N0.getOpcode() == N1.getOpcode()) {
2752827523
// bo (build_vec ..undef, X, undef...), (build_vec ..undef, Y, undef...) -->
27529-
// insert_vector_elt undef, (bo X, Y), index
27530-
27531-
SmallVector<SDValue, 16> EltsX, EltsY;
27524+
// build_vec ..undef, (bo X, Y), undef...
27525+
SmallVector<SDValue, 16> EltsX, EltsY, EltsResult;
2753227526
DAG.ExtractVectorElements(Src0, EltsX);
2753327527
DAG.ExtractVectorElements(Src1, EltsY);
2753427528

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);
27529+
for (auto [X, Y] : zip(EltsX, EltsY))
27530+
EltsResult.push_back(DAG.getNode(Opcode, DL, EltVT, X, Y, N->getFlags()));
27531+
return DAG.getBuildVector(VT, DL, EltsResult);
2754827532
}
2754927533

27534+
SDValue IndexC = DAG.getVectorIdxConstant(Index0, DL);
27535+
SDValue X = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Src0, IndexC);
27536+
SDValue Y = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Src1, IndexC);
27537+
SDValue ScalarBO = DAG.getNode(Opcode, DL, EltVT, X, Y, N->getFlags());
27538+
2755027539
// bo (splat X, Index), (splat Y, Index) --> splat (bo X, Y), Index
2755127540
return DAG.getSplat(VT, DL, ScalarBO);
2755227541
}

0 commit comments

Comments
 (0)