[PATCH] D151416: [NFC][DAGCombiner]: Only consider nodes with no uses for pruning when forming initial worklist
Dhruv Chawla via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 25 03:01:28 PDT 2023
0xdc03 created this revision.
0xdc03 added a reviewer: nikic.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
0xdc03 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
When the worklist is initially being formed, there is no need to
consider all nodes for pruning. This is because the first time calling
getNextWorklistEntry will only clear those nodes which have no uses,
with their operands being added to the worklist. However, when the worklist is
created for the first time all nodes are added anyways, so this operation
actually ends up adding no nodes.
This patch adds a parameter IsCandidateForPruning to AddToWorklist with a
default value of true to avoid having to update every call site.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D151416
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -170,9 +170,15 @@
/// them) when they are deleted from the underlying DAG. It relies on
/// stable indices of nodes within the worklist.
DenseMap<SDNode *, unsigned> WorklistMap;
- /// This records all nodes attempted to add to the worklist since we
+
+ /// This records all nodes attempted to be added to the worklist since we
/// considered a new worklist entry. As we keep do not add duplicate nodes
/// in the worklist, this is different from the tail of the worklist.
+ ///
+ /// Note: All nodes are not added here when the worklist is initially
+ /// formed, this is because the only nodes which can be deleted are those
+ /// which have no uses and all other nodes which would otherwise be added to
+ /// the worklist are already present in it during the initial formation.
SmallSetVector<SDNode *, 32> PruningList;
/// Set of nodes which have been combined (at least once).
@@ -263,7 +269,7 @@
/// Add to the worklist making sure its instance is at the back (next to be
/// processed.)
- void AddToWorklist(SDNode *N) {
+ void AddToWorklist(SDNode *N, bool IsCandidateForPruning = true) {
assert(N->getOpcode() != ISD::DELETED_NODE &&
"Deleted Node added to Worklist");
@@ -272,7 +278,9 @@
if (N->getOpcode() == ISD::HANDLENODE)
return;
- ConsiderForPruning(N);
+ if (IsCandidateForPruning) {
+ ConsiderForPruning(N);
+ }
if (WorklistMap.insert(std::make_pair(N, Worklist.size())).second)
Worklist.push_back(N);
@@ -1771,7 +1779,7 @@
// Add all the dag nodes to the worklist.
for (SDNode &Node : DAG.allnodes())
- AddToWorklist(&Node);
+ AddToWorklist(&Node, Node.use_empty());
// Create a dummy node (which is not added to allnodes), that adds a reference
// to the root node, preventing it from being deleted, and tracking any
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151416.525509.patch
Type: text/x-patch
Size: 2140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230525/80cd1a37/attachment.bin>
More information about the llvm-commits
mailing list