[PATCH] D16197: [LV] Vectorize first-order recurrences

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 11 09:35:31 PST 2016


anemet added inline comments.

================
Comment at: lib/Transforms/Vectorize/LoopVectorize.cpp:3573-3585
@@ +3572,15 @@
+
+  // Get the initial and previous values of the scalar recurrence. First-order
+  // recurrences are of the form "current = phi(initial, previous)".
+  auto *ScalarInit = Phi->getIncomingValue(0);
+  auto *Previous = Phi->getIncomingValue(1);
+  if (!OrigLoop->isLoopInvariant(ScalarInit))
+    std::swap(ScalarInit, Previous);
+
+  // Ensure the previous value is loop-varying and the initial value is
+  // loop-invariant.
+  assert(!OrigLoop->isLoopInvariant(Previous) &&
+         "Previous value is loop-varying");
+  assert(OrigLoop->isLoopInvariant(ScalarInit) &&
+         "Initial value isn't loop-invariant");
+
----------------
mssimpso wrote:
> anemet wrote:
> > This is duplicated between here and isFirstOrderRecurrence, would be nice to somehow remove this.
> Sure, I will delete these assertions here.
I didn't mean this only for the asserts.  I think it would make sense to factor out the way we get the previous and init for a first-order recurrence somewhere (e.g. RecurrenceDescriptor?).

There may also be some common functionality between this new function and RecurrenceDescriptor::isFirstOrderRecurrence that could be shared.



http://reviews.llvm.org/D16197





More information about the llvm-commits mailing list