[PATCH] [SLSR] handle candidate form &B[i * S]

Mark Heffernan meheff at google.com
Wed Mar 11 11:26:51 PDT 2015


================
Comment at: lib/Transforms/Scalar/StraightLineStrengthReduce.cpp:363
@@ +362,3 @@
+    // sign-extended to the pointer size.
+    for (unsigned Stripped = 0; Stripped < 2; ++Stripped) {
+      // At least, ArrayIdx = ArrayIdx *s 1.
----------------
I see that this loop enables you to avoid code duplication for the two cases (sext-wrapped and no sext), but it requires a bit of mental effort to see what it is doing.  I think this would be clearer if you just broke out the code into a separate function and avoided the loop altogether.  Then the code looks like:

foobarfunction(Base, ArrayIdx, ElementSize, GEP)
Value *SextIdx;
if (!match(ArrayIdx, m_SExt(m_Value(SextIdx)))
  foobarfunction(Base, SextIdx, ElementSize, GEP);

In this case it is much more obvious that you're considering the two cases (sext and no sext).  There is one other location in the file which uses this similar style loop construct and might be clearer expressed as a separate function call.

http://reviews.llvm.org/D7459

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






More information about the llvm-commits mailing list