[PATCH] Add straight-line strength reduction to LLVM

Jingyue Wu jingyue at google.com
Fri Jan 30 17:13:17 PST 2015


Hi hfinkel, meheff, eliben, HaoLiu, jholewinski,

Straight-line strength reduction (SLSR) is implemented in GCC but not yet in
LLVM. It has proven to effectively simplify statements derived from an unrolled
loop, and can potentially benefit many other cases too. For example,

LLVM unrolls

#pragma unroll
foo (int i = 0; i < 3; ++i) {
  sum += foo((b + i) * s);
}

into

sum += foo(b * s);
sum += foo((b + 1) * s);
sum += foo((b + 2) * s);

However, no optimizations yet reduce the internal redundancy of the three
expressions:

b * s
(b + 1) * s
(b + 2) * s

With SLSR, LLVM can optimize these three expressions into:

t1 = b * s
t2 = t1 + s
t3 = t2 + s

This commit is only an initial step towards implementing a series of such
optimizations. I will implement more (see TODO in the file commentary) in the
near future. This optimization is enabled for the NVPTX backend for now.
However, I am more than happy to push it to the standard optimization pipeline
after more thorough performance tests.

http://reviews.llvm.org/D7310

Files:
  include/llvm/InitializePasses.h
  include/llvm/LinkAllPasses.h
  include/llvm/Transforms/Scalar.h
  lib/Target/NVPTX/NVPTXTargetMachine.cpp
  lib/Transforms/Scalar/CMakeLists.txt
  lib/Transforms/Scalar/Scalar.cpp
  lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
  test/Transforms/StraightLineStrengthReduce/slsr.ll

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7310.19075.patch
Type: text/x-patch
Size: 16103 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150131/13e31727/attachment.bin>


More information about the llvm-commits mailing list