[SDAG] Make the DAGCombine worklist not grow endlessly due to duplicate
authorChandler Carruth <chandlerc@gmail.com>
Wed, 23 Jul 2014 07:08:53 +0000 (07:08 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Wed, 23 Jul 2014 07:08:53 +0000 (07:08 +0000)
commita6425604c2946855d5e4d732b8d0f714107918b7
tree2fcb449a2c5223b43626110251376850b454083c
parent1bda2d938644901f0608ba63f76eb44ed792a0ee
[SDAG] Make the DAGCombine worklist not grow endlessly due to duplicate
insertions.

The old behavior could cause arbitrarily bad memory usage in the DAG
combiner if there was heavy traffic of adding nodes already on the
worklist to it. This commit switches the DAG combine worklist to work
the same way as the instcombine worklist where we null-out removed
entries and only add new entries to the worklist. My measurements of
codegen time shows slight improvement. The memory utilization is
unsurprisingly dominated by other factors (the IR and DAG itself
I suspect).

This change results in subtle, frustrating churn in the particular order
in which DAG combines are applied which causes a number of minor
regressions where we fail to match a pattern previously matched by
accident. AFAICT, all of these should be using AddToWorklist to directly
or should be written in a less brittle way. None of the changes seem
drastically bad, and a few of the changes seem distinctly better.

A major change required to make this work is to significantly harden the
way in which the DAG combiner handle nodes which become dead
(zero-uses). Previously, we relied on the ability to "priority-bump"
them on the combine worklist to achieve recursive deletion of these
nodes and ensure that the frontier of remaining live nodes all were
added to the worklist. Instead, I've introduced a routine to just
implement that precise logic with no indirection. It is a significantly
simpler operation than that of the combiner worklist proper. I suspect
this will also fix some other problems with the combiner.

I think the x86 changes are really minor and uninteresting, but the
avx512 change at least is hiding a "regression" (despite the test case
being just noise, not testing some performance invariant) that might be
looked into. Not sure if any of the others impact specific "important"
code paths, but they didn't look terribly interesting to me, or the
changes were really minor. The consensus in review is to fix any
regressions that show up after the fact here.

Thanks to the other reviewers for checking the output on other
architectures. There is a specific regression on ARM that Tim already
has a fix prepped to commit.

Differential Revision: http://reviews.llvm.org/D4616

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213727 91177308-0d34-0410-b5e6-96231b3b80d8
16 files changed:
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
test/CodeGen/ARM/fold-stack-adjust.ll
test/CodeGen/ARM/sxt_rot.ll
test/CodeGen/PowerPC/complex-return.ll
test/CodeGen/PowerPC/subsumes-pred-regs.ll
test/CodeGen/R600/r600-export-fix.ll
test/CodeGen/R600/swizzle-export.ll
test/CodeGen/Thumb2/thumb2-sxt_rot.ll
test/CodeGen/Thumb2/thumb2-uxt_rot.ll
test/CodeGen/X86/avx512-zext-load-crash.ll [deleted file]
test/CodeGen/X86/block-placement.ll
test/CodeGen/X86/divide-by-constant.ll
test/CodeGen/X86/fold-pcmpeqd-0.ll [deleted file]
test/CodeGen/X86/narrow-shl-load.ll
test/CodeGen/X86/store-narrow.ll
test/CodeGen/X86/vec_extract-sse4.ll