[PATCH] D57180: [LV] Avoid adding into interleaved group in presence of WAW dependency

Ayal Zaks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 28 06:10:33 PDT 2019


Ayal added a comment.

Here's is an old draft along the lines discussed above, probably deserves some updating or clean ups:

  Index: include/llvm/Analysis/VectorUtils.h
  ===================================================================
  --- include/llvm/Analysis/VectorUtils.h	(revision 352559)
  +++ include/llvm/Analysis/VectorUtils.h	(working copy)
  @@ -303,6 +303,35 @@
       return true;
     }
   
  +  /// Check if a new member \p Instr can be inserted with index \p Index and
  +  /// alignment \p NewAlign. The index is related to the leader and it could be
  +  /// negative if it is the new leader.
  +  ///
  +  /// \returns false if the instruction doesn't belong to the group.
  +  bool insertableMember(InstTy *Instr, int Index, unsigned NewAlign) const {
  +    assert(NewAlign && "The new member's alignment should be non-zero");
  +
  +    int Key = Index + SmallestKey;
  +
  +    // Skip if there is already a member with the same index.
  +    if (Members.find(Key) != Members.end())
  +      return false;
  +
  +    if (Key > LargestKey) {
  +      // The largest index is always less than the interleave factor.
  +      if (Index >= static_cast<int>(Factor))
  +        return false;
  +
  +    } else if (Key < SmallestKey) {
  +      // The largest index is always less than the interleave factor.
  +      if (LargestKey - Key >= static_cast<int>(Factor))
  +        return false;
  +
  +    }
  +
  +    return true;
  +  }
  +
     /// Get the member with the given index \p Index
     ///
     /// \returns nullptr if contains no such member.
  Index: lib/Analysis/VectorUtils.cpp
  ===================================================================
  --- lib/Analysis/VectorUtils.cpp	(revision 352559)
  +++ lib/Analysis/VectorUtils.cpp	(working copy)
  @@ -936,8 +936,23 @@
         BasicBlock *BlockA = A->getParent();  
         BasicBlock *BlockB = B->getParent();  
         if ((isPredicated(BlockA) || isPredicated(BlockB)) &&
  -          (!EnablePredicatedInterleavedMemAccesses || BlockA != BlockB))
  +          (!EnablePredicatedInterleavedMemAccesses || BlockA != BlockB)) {
  +        // If A could be inserted into B's group but is not, prevent a potential
  +        // output dependent unpredicated store from taking its place.
  +        // TODO: mark IndexA "taken", instead of breaking the group, when store
  +        // groups with gaps are supported.
  +        if (Group) {
  +          int IndexA =
  +              Group->getIndex(B) + DistanceToB / static_cast<int64_t>(DesB.Size);
  +          if (Group->insertableMember(A, IndexA, DesA.Align)) {
  +            LLVM_DEBUG(dbgs() << "LV: Detected candidate:" << *A << '\n'
  +                              << "    preventing another for interleave group"
  +                              << " with" << *B << '\n');
  +            break;
  +          }
  +        }
           continue;
  +      }
   
         // The index of A is the index of B plus A's distance to B in multiples
         // of the size.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57180/new/

https://reviews.llvm.org/D57180





More information about the llvm-commits mailing list