[PATCH] D72238: [LegalizeVectorOps] Expand MERGE_VALUES created by custom legalization immediately

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 5 17:02:55 PST 2020


craig.topper created this revision.
craig.topper added reviewers: RKSimon, spatel, efriedma, arsenm.
Herald added subscribers: hiraditya, wdng.
Herald added a project: LLVM.

This matches what we do in LegalizeDAG. This is based on D72224 <https://reviews.llvm.org/D72224>. I had to modify the Custom handling code from that again to support MERGE_VALUES being disintegrated.


https://reviews.llvm.org/D72238

Files:
  llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp


Index: llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
@@ -258,9 +258,15 @@
           assert(Lowered->getNumValues() == Op->getNumValues() &&
                  "Unexpected number of results");
           if (Lowered != SDValue(Node, 0)) {
-            // Make sure the new code is also legal.
-            Lowered = LegalizeOp(Lowered);
             Changed = true;
+
+            // Make sure the new code is also legal.
+            for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i)
+              AddLegalizedOperand(Op.getValue(i),
+                                  LegalizeOp(Lowered.getValue(i)));
+
+            // Map was updated above, return corresponding result.
+            return LegalizedNodes[Op];
           }
           return TranslateLegalizeResults(Op, Lowered.getNode());
         }
@@ -464,6 +470,12 @@
     Action = TLI.getOperationAction(Node->getOpcode(),
                                     Node->getOperand(0).getValueType());
     break;
+  case ISD::MERGE_VALUES:
+    Action = TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0));
+    // This operation lies about being legal: when they claim to be legal,
+    // they should actually be expanded.
+    if (Action == TargetLowering::Legal)
+      Action = TargetLowering::Expand;
   }
 
   LLVM_DEBUG(dbgs() << "\nLegalizing vector op: "; Node->dump(&DAG));
@@ -483,22 +495,28 @@
     if (SDValue Tmp = TLI.LowerOperation(SDValue(Node, 0), DAG)) {
       LLVM_DEBUG(dbgs() << "Successfully custom legalized node\n");
       if (Tmp != SDValue(Node, 0)) {
-        // Make sure that the generated code is itself legal.
-        Tmp = LegalizeOp(Tmp);
         Changed = true;
-      }
 
-      // Tmp might point to a single result from a multi result node, in that
-      // case we need to use it's result number.
-      if (Node->getNumValues() == 1) {
-        AddLegalizedOperand(Op, Tmp);
-        return Tmp;
+        // Tmp might point to a single result from a multi result node, in that
+        // case we need to use it's result number.
+        if (Node->getNumValues() == 1) {
+          Tmp = LegalizeOp(Tmp);
+          AddLegalizedOperand(Op, Tmp);
+          return Tmp;
+        }
+
+        // Otherwise it should be a multi-result node with the same number of
+        // results.
+        assert(Tmp->getNumValues() == Node->getNumValues() &&
+               "Unexpected number of results");
+
+        for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i)
+          AddLegalizedOperand(Op.getValue(i), LegalizeOp(Tmp.getValue(i)));
+
+        // Map was updated above, return corresponding result.
+        return LegalizedNodes[Op];
       }
 
-      // Otherwise it should be a multi-result node with the same number of
-      // results.
-      assert(Tmp->getNumValues() == Node->getNumValues() &&
-             "Unexpected number of results");
       return TranslateLegalizeResults(Op, Tmp.getNode());
     }
     LLVM_DEBUG(dbgs() << "Could not custom legalize node\n");
@@ -821,6 +839,10 @@
 
   SmallVector<SDValue, 8> Results;
   switch (Op->getOpcode()) {
+  case ISD::MERGE_VALUES:
+    for (unsigned i = 0; i != Node->getNumValues(); ++i)
+      Results.push_back(Node->getOperand(i));
+    break;
   case ISD::SIGN_EXTEND_INREG:
     Results.push_back(ExpandSEXTINREG(Op));
     break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72238.236277.patch
Type: text/x-patch
Size: 3520 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200106/104ca4b0/attachment.bin>


More information about the llvm-commits mailing list