[PATCH] Add straight-line strength reduction to LLVM

Jingyue Wu jingyue at google.com
Mon Feb 2 22:25:36 PST 2015


================
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
----------------
hfinkel wrote:
> We don't need to mention GCC here.
done

================
Comment at: lib/Transforms/Scalar/StraightLineStrengthReduce.cpp:166
@@ +165,3 @@
+      C.Basis = &(*Basis);
+      break;
+    }
----------------
meheff wrote:
> Since there can be more than one candidate would there ever be any advantage to looking deeper in the list?  Some bases could be cheaper (eg, where i' - i == 1 and you don't need a multiply).  However, I'd guess in the common unrolled case the latest candidate on the list is best.  On the other hand though, from an ILP perspective the earliest candidate might be best.
We may want to improve the strategy in the future. The patterns I have seen so far are derived from loop unrolling, and in those cases choosing the latest candidate very likely produces the best code. Also note that in the cases where the value grows by a multiple of the stride, e.g., 
```
b * s
(b + 2) * s
(b + 4) * s
```
choosing the latest candidate leads to a uniform bump (`2 * s` in this example) for every iteration, and this bump can be GVN'ed later.  

================
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 +
----------------
hfinkel wrote:
> You can remove the "TODO" part of this. There are a lot of things in LLVM that only handle the canonical operand ordering.
done

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

http://reviews.llvm.org/D7310

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list