[PATCH] D30710: [LV] Vectorize GEPs

Matthew Simpson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 7 13:32:23 PST 2017


mssimpso added inline comments.


================
Comment at: lib/Transforms/Vectorize/LoopVectorize.cpp:4710
+      if (Legal->isUniform(GEP)) {
+        auto *Clone = cast<GetElementPtrInst>(GEP->clone());
+        for (unsigned I = 0; I < GEP->getNumOperands(); ++I)
----------------
mssimpso wrote:
> delena wrote:
> > GEP is uniform when the memory instruction (User) is uniform, right?
> > Why do you need to broadcast it?
> This is "loop-invariant" in the LoopAccessInfo::isUniform sense not in the LoopVectorizationCostModel::isUniformAfterVectorization sense (we really should come up with some better names for these concepts). Sometimes we end up with GEPs contained in the loop body that have loop-invariant operands. I'm not sure why these GEPs aren't hoisted out of the loop before the vectorizer runs.
> 
> In theory, we should be able to hoist these GEPs out of the loop ourselves, but we have assumptions elsewhere that if an instruction existed in the original loop body, it will map to something inside the vectorized loop body. So I just clone and broadcast the original GEP inside the loop here. The change to the first-order-recurrence.ll test case is reflective of this.
I just thought about a different way to implement this. Instead of the uniform check, we could check if the value returned by the IRBuilder has a vector type, and if not, do the broadcast. If all the operands are loop-invariant in the code below, the IRBuilder will return a scalar GEP. This will probably be fewer lines of code anyway. Let me give it a shot.


https://reviews.llvm.org/D30710





More information about the llvm-commits mailing list