[llvm] [SelectionDAG] Convert to or mask if all insertions are -1 (PR #138213)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri May 2 15:53:28 PDT 2025


================
@@ -22973,17 +22973,28 @@ 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) &&
+      // We can convert to AND/OR mask if all insertions are zero or -1
+      // respectively.
+      if (!LegalOperations &&
+          (llvm::isNullConstant(InVal) || llvm::isAllOnesConstant(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);
+
+        // If all insertions are zero value, convert to AND mask.
+        if (llvm::isNullConstant(InVal)) {
----------------
topperc wrote:

I meant the getNode and getBuildVector too.

https://github.com/llvm/llvm-project/pull/138213


More information about the llvm-commits mailing list