Teach the reassociate pass to fold chains of multiplies with repeated
authorChandler Carruth <chandlerc@gmail.com>
Thu, 26 Apr 2012 05:30:30 +0000 (05:30 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Thu, 26 Apr 2012 05:30:30 +0000 (05:30 +0000)
commit464bda3a167bb761eb3c9c178db3fa8ed26fe825
treeb0737bd074f12125c550e88e4c1511fc1b21e6cb
parentcac31de146e7131f411715dc6cb1958ea59bd754
Teach the reassociate pass to fold chains of multiplies with repeated
elements to minimize the number of multiplies required to compute the
final result. This uses a heuristic to attempt to form near-optimal
binary exponentiation-style multiply chains. While there are some cases
it misses, it seems to at least a decent job on a very diverse range of
inputs.

Initial benchmarks show no interesting regressions, and an 8%
improvement on SPASS. Let me know if any other interesting results (in
either direction) crop up!

Credit to Richard Smith for the core algorithm, and helping code the
patch itself.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@155616 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/Reassociate.cpp
test/Transforms/Reassociate/mulfactor.ll