Skip to content

Commit 4c6f15f

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 7e48649 commit 4c6f15f

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27525,36 +27525,25 @@ static SDValue scalarizeBinOpOfSplats(SDNode *N, SelectionDAG &DAG,
2752527525
if ((Opcode == ISD::MULHS || Opcode == ISD::MULHU) && !TLI.isTypeLegal(EltVT))
2752627526
return SDValue();
2752727527

27528-
SDValue IndexC = DAG.getVectorIdxConstant(Index0, DL);
27529-
SDValue X = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Src0, IndexC);
27530-
SDValue Y = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Src1, IndexC);
27531-
SDValue ScalarBO = DAG.getNode(Opcode, DL, EltVT, X, Y, N->getFlags());
27532-
2753327528
// If all lanes but 1 are undefined, no need to splat the scalar result.
2753427529
// TODO: Keep track of undefs and use that info in the general case.
2753527530
if (N0.getOpcode() == ISD::BUILD_VECTOR && N0.getOpcode() == N1.getOpcode()) {
2753627531
// bo (build_vec ..undef, X, undef...), (build_vec ..undef, Y, undef...) -->
27537-
// insert_vector_elt undef, (bo X, Y), index
27538-
27539-
SmallVector<SDValue, 16> EltsX, EltsY;
27532+
// build_vec ..undef, (bo X, Y), undef...
27533+
SmallVector<SDValue, 16> EltsX, EltsY, EltsResult;
2754027534
DAG.ExtractVectorElements(Src0, EltsX);
2754127535
DAG.ExtractVectorElements(Src1, EltsY);
2754227536

27543-
SmallVector<SDValue, 16> EltsResult;
27544-
27545-
unsigned NonUndefElements = 0;
27546-
for (auto [X, Y] : zip(EltsX, EltsY)) {
27547-
SDValue ScalarBO = DAG.getNode(Opcode, DL, EltVT, X, Y, N->getFlags());
27548-
if (!ScalarBO.isUndef())
27549-
if (NonUndefElements++ > 1)
27550-
break;
27551-
EltsResult.push_back(ScalarBO);
27552-
}
27553-
27554-
if (NonUndefElements == 1)
27555-
return DAG.getBuildVector(VT, DL, EltsResult);
27537+
for (auto [X, Y] : zip(EltsX, EltsY))
27538+
EltsResult.push_back(DAG.getNode(Opcode, DL, EltVT, X, Y, N->getFlags()));
27539+
return DAG.getBuildVector(VT, DL, EltsResult);
2755627540
}
2755727541

27542+
SDValue IndexC = DAG.getVectorIdxConstant(Index0, DL);
27543+
SDValue X = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Src0, IndexC);
27544+
SDValue Y = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Src1, IndexC);
27545+
SDValue ScalarBO = DAG.getNode(Opcode, DL, EltVT, X, Y, N->getFlags());
27546+
2755827547
// bo (splat X, Index), (splat Y, Index) --> splat (bo X, Y), Index
2755927548
return DAG.getSplat(VT, DL, ScalarBO);
2756027549
}

0 commit comments

Comments
 (0)