Skip to content

Conversation

@jcohen-apple
Copy link
Contributor

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.

@llvmbot llvmbot added the llvm:SelectionDAG SelectionDAGISel as well label Nov 13, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 13, 2024

@llvm/pr-subscribers-llvm-selectiondag

Author: Jonathan Cohen (jcohen-apple)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/116030.diff

1 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (+2-1)
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;
       }
     }

SmallVector<const SDNode *, 2> Worklist;
Worklist.push_back(Use);
if (SDNode::hasPredecessorHelper(N, Visited, Worklist))
constexpr unsigned int MaxSteps = 8192;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big number to repeat multiple times. Move these to a common constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to be a hidden cl option in case someone would like to play with it later, and defaulted to 8192. WDYT?

@jcohen-apple jcohen-apple force-pushed the dev/jcohen/limit_steps_in_post_inc_combine branch 2 times, most recently from 4246b28 to 787ab75 Compare November 17, 2024 09:58
@jcohen-apple jcohen-apple force-pushed the dev/jcohen/limit_steps_in_post_inc_combine branch 3 times, most recently from 6eadbbd to 2790a3d Compare November 20, 2024 08:01
Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - cheers

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.
@jcohen-apple jcohen-apple force-pushed the dev/jcohen/limit_steps_in_post_inc_combine branch from 2790a3d to 79a709c Compare November 21, 2024 08:54
@jcohen-apple jcohen-apple merged commit 00d383e into llvm:main Nov 21, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:SelectionDAG SelectionDAGISel as well

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants