[PATCH] D18798: New code hoisting pass based on GVN

Sebastian Pop via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 8 15:03:34 PDT 2016


sebpop removed rL LLVM as the repository for this revision.
sebpop updated this revision to Diff 53095.
sebpop added a comment.

In http://reviews.llvm.org/D18798#394160, @chandlerc wrote:

> - We also would likely need to see a reasonable analysis of the effect this has on compile time so we understand the tradeoff this is making. My suspicion is that it won't be the correct tradeoff for O2 if it is correct at any level. (See below.) [...]  It makes very little sense IMO to do early-cse and then early-gvn... The only point of early-cse was to be a substantially lighter weight CSE than GVN. If you're going to run GVN anyways to do hoisting, just run GVN.


I think there is a misconception of "GVN == PRE": this is because GVN.cpp was
around for a while and the "GVN pass" is a "redundancy elimination" pass.

To clarify matters, GVN is an analysis pass, like SCEV or data dependence are
analysis passes. What GVN does is similar to what md5 does to a text file:
given an instruction, GVN returns a unique integer identifying what the compiler
safely estimates as identical computations.

Our pass uses GVN as an analysis pass to perform code hoisting. CSE removes
redundant computations (same expression computed twice over the same execution
path.) Code hoisting does not remove redundancies: it replaces several identical
expressions executed exactly once on all execution paths with a single
expression placed in a common dominator block. Code hoisting, like CSE, is good
for code size reduction: it improves inlining heuristics by reducing the size of
function bodies.

Over the c/c++ SPEC 2006 benchmarks the GVN-hoisting pass removes 16161
instructions, 4622 loads and 11539 scalar instructions.  Overall spec scores
improve with the patch except for bzip2 and gcc:

CINT2006:
400.perlbench  2.4%
401.bzip2     -0.9%
403.gcc       -1%
429.mcf        6%
445.gobmk      1%
456.hmmer      0%
458.sjeng      1%
462.libquantum 4.6%
464.h264ref    0.6%
471.omnetpp    1.5%
473.astar      1.9%
483.xalancbmk  llvm trunk coredumps

CFP2006:
433.milc       0%
444.namd       0.8%
447.dealII     0%
450.soplex     2.8%
453.povray     1%
470.lbm        2.6%
482.sphinx3    3.9%

Compile time statistics for the c/c++ benchmarks of SPEC2006 show that overall
there are more functions inlined:

- Without the patch:

Number of call sites deleted, not inlined: 20394
Number of functions deleted because all callers found: 70497
Number of functions inlined: 182119
Number of allocas merged together: 225
Number of caller-callers analyzed: 200361
Number of call sites analyzed: 445806

- With the patch:

Number of call sites deleted, not inlined: 20419
Number of functions deleted because all callers found: 70502
Number of functions inlined: 182449
Number of allocas merged together: 227
Number of caller-callers analyzed: 200929
Number of call sites analyzed: 446858
Number of hoisted loads: 4622
Number of hoisted scalar instructions: 11539

Compilation time is not impacted compiling nightly test-suite with a clang
configured in release mode:

llvm-trunk $ /usr/bin/time ninja -j1
355.80user 16.30system 6:24.47elapsed 96%CPU (0avgtext+0avgdata 285796maxresident)k
64inputs+291368outputs (7major+10867361minor)pagefaults 0swaps

patch $ /usr/bin/time ninja -j1
355.34user 15.55system 6:24.26elapsed 96%CPU (0avgtext+0avgdata 286008maxresident)k
94568inputs+290792outputs (453major+10921164minor)pagefaults 0swaps

I have renamed the new pass GVN-hoist to avoid further confusion. I think it
would be good in the NewGVN that Danny is pushing to trunk to have a clear
distinction of the GVN analysis with a clear interface that can be used by
transforms other than GVN-PRE. IMO forcing the GVN.cpp file to only contain the
analysis and pushing the other transforms out in different files would achieve
more clarity in the use of GVN analysis.


http://reviews.llvm.org/D18798

Files:
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/LinkAllPasses.h
  llvm/include/llvm/Transforms/Scalar.h
  llvm/include/llvm/Transforms/Scalar/GVN.h
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/lib/Transforms/Scalar/CMakeLists.txt
  llvm/lib/Transforms/Scalar/GVNHoist.cpp
  llvm/lib/Transforms/Scalar/Scalar.cpp
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/GVN/hoist.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18798.53095.patch
Type: text/x-patch
Size: 31419 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160408/b364efec/attachment.bin>


More information about the llvm-commits mailing list