[PATCH] D62633: Recommit r360171: [DAGCombiner] Avoid creating large tokenfactors in visitTokenFactor.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 29 20:13:31 PDT 2019

fhahn updated this revision to Diff 202109.
fhahn added a comment.

In D62633#1522239 <https://reviews.llvm.org/D62633#1522239>, @niravd wrote:

> Can you get away with just adding all remaining TFs (not their operands) to Ops? That way we keep the TF smaller and the pruning search still happens. That seems sufficient to fix the dropped operator issue.

Yes we can, kind of. If we just add all remaining TFs, we might get stuck in a loop, because in some cases the simplified TokenFactor == N and N gets added to the worklist, because it is the single user of another tokenfactor. I changed it to expand the first outstanding tokenfactor and add the remaining ones unexpanded. THat way, we should not get stuck in a loop, while keeping the size small.

What do you think?

  rG LLVM Github Monorepo




Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -1801,8 +1801,22 @@
   // Iterate through token factors.  The TFs grows when new token factors are
   // encountered.
   for (unsigned i = 0; i < TFs.size(); ++i) {
-    SDNode *TF = TFs[i];
+    // Limit number of nodes to inline, to avoid quadratic compile times.
+    // We have to add the outstanding tokenfactors to Ops, otherwise we might
+    // drop Ops from the resulting tokenfactor.
+    if (Ops.size() > 2048) {
+      // Expand first outstanding tokenfactor, to ensure we create a changed
+      // node. Otherwise, in some cases we might return an unchanged tokenfactor
+      // and we can get stuck in a cycle.
+      for (const SDValue &Op : TFs[i]->op_values())
+        Ops.push_back(Op);
+      // Add remaining tokenfactors directly.
+      for (i++; i < TFs.size(); i++)
+        Ops.emplace_back(TFs[i], 0);
+      break;
+    }
+    SDNode *TF = TFs[i];
     // Check each of the operands.
     for (const SDValue &Op : TF->op_values()) {
       switch (Op.getOpcode()) {

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62633.202109.patch
Type: text/x-patch
Size: 1222 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190530/f5b983fe/attachment.bin>

More information about the llvm-commits mailing list