@@ -23811,6 +23811,7 @@ SDValue DAGCombiner::reduceBuildVecToShuffle(SDNode *N) {
23811
23811
// value.
23812
23812
unsigned OneConstExtractIndex = ~0u;
23813
23813
23814
+ // Count the number of extract_vector_elt sources (i.e. non-constant or undef)
23814
23815
unsigned NumExtracts = 0;
23815
23816
23816
23817
for (unsigned i = 0; i != NumElems; ++i) {
@@ -23849,9 +23850,7 @@ SDValue DAGCombiner::reduceBuildVecToShuffle(SDNode *N) {
23849
23850
ExtractedFromVec.getValueType().getVectorElementType())
23850
23851
return SDValue();
23851
23852
23852
- if (OneConstExtractIndex == ~0u)
23853
- OneConstExtractIndex = ExtractIdx->getZExtValue();
23854
-
23853
+ OneConstExtractIndex = ExtractIdx->getZExtValue();
23855
23854
++NumExtracts;
23856
23855
23857
23856
// Have we seen this input vector before?
@@ -23878,14 +23877,16 @@ SDValue DAGCombiner::reduceBuildVecToShuffle(SDNode *N) {
23878
23877
if (VecIn.size() == 2) {
23879
23878
// If we only found a single constant indexed extract_vector_elt feeding the
23880
23879
// build_vector, do not produce a more complicated shuffle if the extract is
23881
- // cheap.
23882
-
23883
- // TODO: This should be more aggressive about skipping the shuffle formation
23884
- // (e.g., always do this for VecIn[1]->hasOneUse())
23885
- if (TLI.isOperationLegalOrCustom(ISD::EXTRACT_VECTOR_ELT, VT) &&
23880
+ // cheap with other constant/undef elements. Skip broadcast patterns with
23881
+ // multiple uses in the build_vector.
23882
+
23883
+ // TODO: This should be more aggressive about skipping the shuffle
23884
+ // formation, particularly if VecIn[1].hasOneUse(), and regardless of the
23885
+ // index.
23886
+ if (NumExtracts == 1 &&
23887
+ TLI.isOperationLegalOrCustom(ISD::EXTRACT_VECTOR_ELT, VT) &&
23886
23888
TLI.isTypeLegal(VT.getVectorElementType()) &&
23887
- // VecIn[1].hasOneUse() &&
23888
- NumExtracts == 1 && TLI.isExtractVecEltCheap(VT, OneConstExtractIndex))
23889
+ TLI.isExtractVecEltCheap(VT, OneConstExtractIndex))
23889
23890
return SDValue();
23890
23891
23891
23892
unsigned MaxIndex = 0;
0 commit comments