Skip to content

Commit

Permalink
[DAG] Fold multiple insert_vector_elt of zero values into an AND mask
Browse files Browse the repository at this point in the history
This also allows us to make use of the existing isVectorClearMaskLegal shuffle canonicalization

Differential Revision: https://reviews.llvm.org/D145939
  • Loading branch information
RKSimon committed Mar 15, 2023
1 parent 71c4d18 commit 7056260
Show file tree
Hide file tree
Showing 6 changed files with 844 additions and 1,215 deletions.
14 changes: 14 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20982,6 +20982,20 @@ SDValue DAGCombiner::visitINSERT_VECTOR_ELT(SDNode *N) {
return NewShuffle;
}

// If all insertions are zero value, try to convert to AND mask.
// TODO: Do this for -1 with OR mask?
if (!LegalOperations && llvm::isNullConstant(InVal) &&
all_of(Ops, [InVal](SDValue Op) { return !Op || Op == InVal; }) &&
count_if(Ops, [InVal](SDValue Op) { return Op == InVal; }) >= 2) {
SDValue Zero = DAG.getConstant(0, DL, MaxEltVT);
SDValue AllOnes = DAG.getAllOnesConstant(DL, MaxEltVT);
SmallVector<SDValue, 8> Mask(NumElts);
for (unsigned I = 0; I != NumElts; ++I)
Mask[I] = Ops[I] ? Zero : AllOnes;
return DAG.getNode(ISD::AND, DL, VT, CurVec,
DAG.getBuildVector(VT, DL, Mask));
}

// Failed to find a match in the chain - bail.
break;
}
Expand Down

0 comments on commit 7056260

Please sign in to comment.