[PATCH] D25557: [LAA] Collect pointers with unknown bounds

Evgeny Astigeevich via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 19 04:52:26 PDT 2016

eastig added a comment.

In https://reviews.llvm.org/D25557#573719, @anemet wrote:

> > This is an enhancement to LoopAccessAnalysis which enables collecting pointers with unknown bounds. Users of LAA can be interested in them.
> Please describe the actual use case.  We're complicating the interface and we need to know if this is worthwhile.

The use case is provided here: https://reviews.llvm.org/D24934
I am splitting it into a set of patches.
I want to reuse the results of LAA. Of course I can copy the code from LAA into the "Loop versioning for LICM" pass but I don't want to do this.

> Please also describe how this work with LoopVersioning (Transform/Util/).  Does it pick up the unknown bounds pointers and generate some some sort of run-time checks for them?

LoopVersioning uses checks either from LAI or user provided ones:

  /// \brief Expects LoopAccessInfo, Loop, LoopInfo, DominatorTree as input.
  /// It uses runtime check provided by the user. If \p UseLAIChecks is true,
  /// we will retain the default checks made by LAI. Otherwise, construct an
  /// object having no checks and we expect the user to add them.
  LoopVersioning(const LoopAccessInfo &LAI, Loop *L, LoopInfo *LI,
                 DominatorTree *DT, ScalarEvolution *SE,
                 bool UseLAIChecks = true);
  /// \brief Sets the runtime alias checks for versioning the loop.
  void setAliasChecks(
      SmallVector<RuntimePointerChecking::PointerCheck, 4> Checks);

When there are pointers with unknown bounds RT checks are not created because CanDoRT is false.
My understanding is that it's a user responsibility to guarantee RT checks are not empty. It's based on the following and current use cases where checks are tested not to be empty:

  BasicBlock* LoopVersioning::versionLoop(
      const SmallVectorImpl<Instruction *> &DefsUsedOutside) {
    std::tie(FirstCheckInst, MemRuntimeCheck) =
        LAI.addRuntimeChecks(RuntimeCheckBB->getTerminator(), AliasChecks);
    if (MemRuntimeCheck && SCEVRuntimeCheck) {
      RuntimeCheck = BinaryOperator::Create(Instruction::Or, MemRuntimeCheck,
                                            SCEVRuntimeCheck, "lver.safe");
      if (auto *I = dyn_cast<Instruction>(RuntimeCheck))
    } else
      RuntimeCheck = MemRuntimeCheck ? MemRuntimeCheck : SCEVRuntimeCheck;
    assert(RuntimeCheck && "called even though we don't need "
                           "any runtime checks");

When LAI.addRuntimeChecks is called for empty checks MemRuntimeCheck is nullptr. So if a user correctly uses LoopVersioning nothing will happen in case of pointers with unknown bounds. There should not be any call of versionLoop. Incorrect uses will cause the assertion failure.

There is also a separate review request regarding to LoopVersioning changes: https://reviews.llvm.org/D25559

> On PtrsWithUnknownBounds, you need to expose this in LAA::print and also write tests for directly using -loop-accesses -analyzes (see tests/Analysis/LoopAccessAnalysis).

I'll do this.


More information about the llvm-commits mailing list