[PATCH] D65614: [Reassociate] Stop linearizing all associative expression trees w/o profitability

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 15:34:08 PDT 2019


reames created this revision.
reames added reviewers: craig.topper, spatel, RKSimon, andreadb.
Herald added subscribers: jfb, dmgreen, bollu, mcrosier.
Herald added a project: LLVM.

The Reassociate pass currently does two things.  First, it factors out common sub-expressions and otherwise *optimizes* the expression tree.  Second, it blindly linearizes the result, regardless of whether any *optimizations* were performed.

This second part is problematic, as we don't have a robust scheduler anywhere else in the pipeline, and a linear execution order is distinctly non-optimal on modern CPUs.  Consider the following (toy) example:
for (int i = 0; i < N; i++) {

  int tmp = a[i];
  tmp += b;
  acquire_fence();
  sum += tmp;

}

In this case, we end up with a nicely unrolled loop, but due to the linearization of the add expressions, we emit a long chain of additions with a single target register.  This form bottlenecks in the scheduler on modern X86 chips for a 25% performance slow down over the original form.

Note that to do this, I had remove a stale piece of code which tried to aggressively re-try expression formation after removing uses.  Given that code has been disabled since 2012, I'm not too worried about that.

An alternate approach to this problem would be to invest in building a scheduler for associative expressions which can properly balance ILP and register pressure.  I'm hoping not to have to solve that problem.  :)

NOTE: This patch does not yet include all required test updates.  A bunch of the tests were not auto-generated, so I need to go autogen them and then rebase.  I don't expect the results will be interesting.


Repository:
  rL LLVM

https://reviews.llvm.org/D65614

Files:
  lib/Transforms/Scalar/Reassociate.cpp
  test/Transforms/Reassociate/basictest.ll
  test/Transforms/Reassociate/factorize-again.ll
  test/Transforms/Reassociate/fast-ReassociateVector.ll
  test/Transforms/Reassociate/fast-basictest.ll
  test/Transforms/Reassociate/matching-binops.ll
  test/Transforms/Reassociate/pointer-collision-non-determinism.ll
  test/Transforms/Reassociate/reassociate_dbgvalue_discard.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65614.212915.patch
Type: text/x-patch
Size: 35884 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190801/3b1994ed/attachment.bin>


More information about the llvm-commits mailing list