llvm/test
Michael Zolotukhin a538be3ab1 [Unroll] Implement a conservative and monotonically increasing cost tracking system during the full unroll heuristic analysis that avoids counting any instruction cost until that instruction becomes "live" through a side-effect or use outside the...
Summary:
...loop after the last iteration.

This is really hard to do correctly. The core problem is that we need to
model liveness through the induction PHIs from iteration to iteration in
order to get the correct results, and we need to correctly de-duplicate
the common subgraphs of instructions feeding some subset of the
induction PHIs. All of this can be driven either from a side effect at
some iteration or from the loop values used after the loop finishes.

This patch implements this by storing the forward-propagating analysis
of each instruction in a cache to recall whether it was free and whether
it has become live and thus counted toward the total unroll cost. Then,
at each sink for a value in the loop, we recursively walk back through
every value that feeds the sink, including looping back through the
iterations as needed, until we have marked the entire input graph as
live. Because we cache this, we never visit instructions more than twice
-- once when we analyze them and put them into the cache, and once when
we count their cost towards the unrolled loop. Also, because the cache
is only two bits and because we are dealing with relatively small
iteration counts, we can store all of this very densely in memory to
avoid this from becoming an excessively slow analysis.

The code here is still pretty gross. I would appreciate suggestions
about better ways to factor or split this up, I've stared too long at
the algorithmic side to really have a good sense of what the design
should probably look at.

Also, it might seem like we should do all of this bottom-up, but I think
that is a red herring. Specifically, the simplification power is *much*
greater working top-down. We can forward propagate very effectively,
even across strange and interesting recurrances around the backedge.
Because we use data to propagate, this doesn't cause a state space
explosion. Doing this level of constant folding, etc, would be very
expensive to do bottom-up because it wouldn't be until the last moment
that you could collapse everything. The current solution is essentially
a top-down simplification with a bottom-up cost accounting which seems
to get the best of both worlds. It makes the simplification incremental
and powerful while leaving everything dead until we *know* it is needed.

Finally, a core property of this approach is its *monotonicity*. At all
times, the current UnrolledCost is a conservatively low estimate. This
ensures that we will never early-exit from the analysis due to exceeding
a threshold when if we had continued, the cost would have gone back
below the threshold. These kinds of bugs can cause incredibly hard to
track down random changes to behavior.

We could use a techinque similar (but much simpler) within the inliner
as well to avoid considering speculated code in the inline cost.

Reviewers: chandlerc

Subscribers: sanjoy, mzolotukhin, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269388 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 01:42:39 +00:00
..
Analysis [SCEVExpander] Fix a failed cast<> assertion 2016-05-11 17:41:41 +00:00
Assembler Make "@name =" mandatory for globals in .ll files. 2016-05-10 18:22:45 +00:00
Bindings [OCaml] Update core test and re-enable testing 2016-05-10 11:19:20 +00:00
Bitcode AMDGPU/SI: Add amdgpu_kernel calling convention. Part 1. 2016-05-06 09:07:29 +00:00
BugPoint [PR27284] Reverse the ownership between DICompileUnit and DISubprogram. 2016-04-15 15:57:41 +00:00
CodeGen [ARM] Fixup tests to take into account mov translation. NFC. 2016-05-12 21:22:37 +00:00
DebugInfo Debug Info: Prevent DW_AT_abstract_origin from being emitted twice 2016-05-10 19:38:51 +00:00
Examples
ExecutionEngine [powerpc] mark JIT tests as UNSUPPORTED on powerpc64 big endian 2016-04-26 03:59:19 +00:00
Feature Make "@name =" mandatory for globals in .ll files. 2016-05-10 18:22:45 +00:00
FileCheck
Instrumentation Add missing tests for new PM 2016-05-10 23:37:19 +00:00
Integer Make "@name =" mandatory for globals in .ll files. 2016-05-10 18:22:45 +00:00
JitListener [PR27284] Reverse the ownership between DICompileUnit and DISubprogram. 2016-04-15 15:57:41 +00:00
LibDriver LibDriver: Silently do nothing when provided no inputs. 2016-04-13 19:36:04 +00:00
Linker Make "@name =" mandatory for globals in .ll files. 2016-05-10 18:22:45 +00:00
LTO Allow the LTO code generator to strip invalid debug info from the input. 2016-05-09 19:57:15 +00:00
MC [ARM] Support and tests for transform of LDR rt, = to MOV 2016-05-12 21:22:42 +00:00
Object Clean up the specific error message for a malformed Mach-O files with bad segment 2016-05-05 17:43:35 +00:00
ObjectYAML [yaml2macho] Handle mach_header_64 reserved field 2016-05-12 18:21:09 +00:00
Other Add opt-bisect support to additional passes that can be skipped 2016-05-03 22:32:30 +00:00
SymbolRewriter
TableGen Introduce a "patchable-function" function attribute 2016-04-19 05:24:47 +00:00
ThinLTO/X86 [ThinLTO] Add option to emit imports files for distributed backends 2016-05-10 15:54:09 +00:00
tools dsymutil: Fix the DWOId mismatch check for cached modules. 2016-05-13 00:17:58 +00:00
Transforms [Unroll] Implement a conservative and monotonically increasing cost tracking system during the full unroll heuristic analysis that avoids counting any instruction cost until that instruction becomes "live" through a side-effect or use outside the... 2016-05-13 01:42:39 +00:00
Unit Replace hardcoded comment at 'lit.site.cfg.in' 2016-04-16 06:47:41 +00:00
Verifier All llvm.deoptimize declarations must use the same calling convention 2016-05-12 01:17:38 +00:00
YAMLParser
.clang-format
CMakeLists.txt Moving llvm-test-depends and test-depends into the Tests folder; NFC, this simply cleans up the generated solution so that these targets don't live in the root folder of the IDE. 2016-04-12 15:09:14 +00:00
lit.cfg Add llvm-pdbdump to the tool substitutions list in lit. NFC. 2016-05-02 16:51:26 +00:00
lit.site.cfg.in Replace hardcoded comment at 'lit.site.cfg.in' 2016-04-16 06:47:41 +00:00
TestRunner.sh