diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2014-07-24 22:15:28 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2014-07-24 22:15:28 +0000 |
commit | 9f4530b95dce63c7f335001d0f955e36e57df88a (patch) | |
tree | 2e9bf3762223effe70e8ab8ce6bd570105930b84 /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | |
parent | 80b869461e7adb6504480f92447e6aef2fbe921e (diff) | |
download | bcm5719-llvm-9f4530b95dce63c7f335001d0f955e36e57df88a.tar.gz bcm5719-llvm-9f4530b95dce63c7f335001d0f955e36e57df88a.zip |
[SDAG] Introduce a combined set to the DAG combiner which tracks nodes
which have successfully round-tripped through the combine phase, and use
this to ensure all operands to DAG nodes are visited by the combiner,
even if they are only added during the combine phase.
This is critical to have the combiner reach nodes that are *introduced*
during combining. Previously these would sometimes be visited and
sometimes not be visited based on whether they happened to end up on the
worklist or not. Now we always run them through the combiner.
This fixes quite a few bad codegen test cases lurking in the suite while
also being more principled. Among these, the TLS codegeneration is
particularly exciting for programs that have this in the critical path
like TSan-instrumented binaries (although I think they engineer to use
a different TLS that is faster anyways).
I've tried to check for compile-time regressions here by running llc
over a merged (but not LTO-ed) clang bitcode file and observed at most
a 3% slowdown in llc. Given that this is essentially a worst case (none
of opt or clang are running at this phase) I think this is tolerable.
The actual LTO case should be even less costly, and the cost in normal
compilation should be negligible.
With this combining logic, it is possible to re-legalize as we combine
which is necessary to implement PSHUFB formation on x86 as
a post-legalize DAG combine (my ultimate goal).
Differential Revision: http://reviews.llvm.org/D4638
llvm-svn: 213898
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index b526523063b..379ea7f7f09 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -104,6 +104,12 @@ namespace { /// stable indices of nodes within the worklist. DenseMap<SDNode *, unsigned> WorklistMap; + /// \brief Set of nodes which have been combined (at least once). + /// + /// This is used to allow us to reliably add any operands of a DAG node + /// which have not yet been combined to the worklist. + SmallPtrSet<SDNode *, 64> CombinedNodes; + // AA - Used for DAG load/store alias analysis. AliasAnalysis &AA; @@ -136,6 +142,8 @@ namespace { /// removeFromWorklist - remove all instances of N from the worklist. /// void removeFromWorklist(SDNode *N) { + CombinedNodes.erase(N); + auto It = WorklistMap.find(N); if (It == WorklistMap.end()) return; // Not in the worklist. @@ -1152,6 +1160,17 @@ void DAGCombiner::Run(CombineLevel AtLevel) { if (recursivelyDeleteUnusedNodes(N)) continue; + DEBUG(dbgs() << "\nCombining: "; + N->dump(&DAG)); + + // Add any operands of the new node which have not yet been combined to the + // worklist as well. Because the worklist uniques things already, this + // won't repeatedly process the same operand. + CombinedNodes.insert(N); + for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) + if (!CombinedNodes.count(N->getOperand(i).getNode())) + AddToWorklist(N->getOperand(i).getNode()); + WorklistRemover DeadNodes(*this); SDValue RV = combine(N); @@ -1172,11 +1191,8 @@ void DAGCombiner::Run(CombineLevel AtLevel) { RV.getNode()->getOpcode() != ISD::DELETED_NODE && "Node was deleted but visit returned new node!"); - DEBUG(dbgs() << "\nReplacing.3 "; - N->dump(&DAG); - dbgs() << "\nWith: "; - RV.getNode()->dump(&DAG); - dbgs() << '\n'); + DEBUG(dbgs() << " ... into: "; + RV.getNode()->dump(&DAG)); // Transfer debug value. DAG.TransferDbgValues(SDValue(N, 0), RV); |