]> granicus.if.org Git - llvm/commitdiff
[DAGCombiner] Make the combine of INSERT_SUBVECTOR into a CONCAT_VECTOR more generic...
authorCraig Topper <craig.topper@gmail.com>
Sat, 11 Feb 2017 22:57:09 +0000 (22:57 +0000)
committerCraig Topper <craig.topper@gmail.com>
Sat, 11 Feb 2017 22:57:09 +0000 (22:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294875 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

index 3a71a5ddb0ef0c2232d99baae5472a47e80ba23c..63e2bd09371be898f78a2dfae0e47f5aacebd5f6 100644 (file)
@@ -14587,23 +14587,16 @@ SDValue DAGCombiner::visitINSERT_SUBVECTOR(SDNode *N) {
     }
   }
 
-  if (N0.getValueType() != N1.getValueType())
-    return SDValue();
-
   // If the input vector is a concatenation, and the insert replaces
-  // one of the halves, we can optimize into a single concat_vectors.
-  if (N0.getOpcode() == ISD::CONCAT_VECTORS && N0->getNumOperands() == 2) {
-    // Lower half: fold (insert_subvector (concat_vectors X, Y), Z) ->
-    // (concat_vectors Z, Y)
-    if (InsIdx == 0)
-      return DAG.getNode(ISD::CONCAT_VECTORS, SDLoc(N), VT, N1,
-                         N0.getOperand(1));
-
-    // Upper half: fold (insert_subvector (concat_vectors X, Y), Z) ->
-    // (concat_vectors X, Z)
-    if (InsIdx == VT.getVectorNumElements() / 2)
-      return DAG.getNode(ISD::CONCAT_VECTORS, SDLoc(N), VT, N0.getOperand(0),
-                         N1);
+  // one of the pieces, we can optimize into a single concat_vectors.
+  if (N0.getOpcode() == ISD::CONCAT_VECTORS && N0.hasOneUse() &&
+      N0.getOperand(0).getValueType() == N1.getValueType()) {
+    unsigned Factor = N1.getValueType().getVectorNumElements();
+
+    SmallVector<SDValue, 8> Ops(N0->op_begin(), N0->op_end());
+    Ops[cast<ConstantSDNode>(N2)->getZExtValue() / Factor] = N1;
+
+    return DAG.getNode(ISD::CONCAT_VECTORS, SDLoc(N), VT, Ops);
   }
 
   return SDValue();