[llvm] [DAGCombiner] Limit steps in shouldCombineToPostInc (PR #116030)

Jonathan Cohen via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 13 03:43:13 PST 2024


https://github.com/jcohen-apple created https://github.com/llvm/llvm-project/pull/116030

Currently the function will walk the entire DAG to find other candidates to perform a post-inc store. This leads to very long compilation times on large functions. Added a MaxSteps limit to avoid this, which is also aligned to how hasPredecessorHelper is used elsewhere in the code.

>From 6e025fefcda9b9b0daac9b3d2ba87c56ad09e61f Mon Sep 17 00:00:00 2001
From: Jonathan Cohen <jcohen22 at apple.com>
Date: Wed, 13 Nov 2024 11:56:06 +0200
Subject: [PATCH] [DAGCombiner] Limit steps in shouldCombineToPostInc

Currently the function will walk the entire DAG to find other
candidates to perform a post-inc store. This leads to very long
compilation times on large functions. Added a MaxSteps limit to
avoid this, which is also aligned to how hasPredecessorHelper is
used elsewhere in the code.
---
 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 6059229cd6d9a4..cc51aed40003f0 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -19089,7 +19089,8 @@ static bool shouldCombineToPostInc(SDNode *N, SDValue Ptr, SDNode *PtrUse,
                                    IsMasked, OtherPtr, TLI)) {
         SmallVector<const SDNode *, 2> Worklist;
         Worklist.push_back(Use);
-        if (SDNode::hasPredecessorHelper(N, Visited, Worklist))
+        constexpr unsigned int MaxSteps = 8192;
+        if (SDNode::hasPredecessorHelper(N, Visited, Worklist, MaxSteps))
           return false;
       }
     }



More information about the llvm-commits mailing list