[PATCH] Add straight-line strength reduction to LLVM

hfinkel at anl.gov hfinkel at anl.gov
Sat Jan 31 00:38:01 PST 2015

Thanks for working on this! We need to be careful here, however, because:

1. We don't want to turn "free" computations into non-free computations (because we remove the ability to do address-mode folding). LoopStrengthReduce uses part of the TTI interface for dealing with target addressing modes, and we should do that here too.
2. We don't want to lengthen the critical path by unnecessarily decreasing the amount of available ILP. We don't currently have a good interface for asking a target how much ILP is available for simple integer operations (we have one for vectorization interleaving factors, which is similar in spirit, but on several targets with which I work, use a different number than would be appropriate here).

Regarding (2), we could also decide the long chain is the canonical form, and targets should split these late for ILP. I've not given this a lot of thought, and so I'm not sure how easy or hard that might be. Using the MachineCombiner might be a good place to do such splitting.

What do you think?

Comment at: lib/Transforms/Scalar/StraightLineStrengthReduce.cpp:11
@@ +10,3 @@
+// This file implements straight-line strength reduction (SLSR), which already
+// exists in GCC. Unlike loop strength reduction, this algorithm is designed to
+// reduce arithmetic redundancy in straight-line code instead of loops. It has
We don't need to mention GCC here.

Comment at: lib/Transforms/Scalar/StraightLineStrengthReduce.cpp:182
@@ +181,3 @@
+      for (unsigned Swapped = 0; Swapped < 2; ++Swapped) {
+        // TODO(jingyue): The reassociation pass places the constant in an
+        // addition at the right hand side. Therefore, we most likely see (a +
You can remove the "TODO" part of this. There are a lot of things in LLVM that only handle the canonical operand ordering.

Comment at: lib/Transforms/Scalar/StraightLineStrengthReduce.cpp:210
@@ +209,3 @@
+  // instruction is already rewritten.
+  if (C.Ins->getParent() == nullptr) {
+    return;
If (!C.Ins->getParent()) is fine. Also no { } needed.



More information about the llvm-commits mailing list