diff --git a/llvm/include/llvm/Transforms/Utils/LoopVersioning.h b/llvm/include/llvm/Transforms/Utils/LoopVersioning.h --- a/llvm/include/llvm/Transforms/Utils/LoopVersioning.h +++ b/llvm/include/llvm/Transforms/Utils/LoopVersioning.h @@ -75,6 +75,12 @@ /// loop may alias (i.e. one of the memchecks failed). Loop *getNonVersionedLoop() { return NonVersionedLoop; } + /// Returns the basic block that contains the runtime check BranchInst + BasicBlock *getRuntimeCheckBB() { return RuntimeCheckBB; } + + /// Returns the runtime check BranchInst + BranchInst *getRuntimeCheckBI() { return RuntimeCheckBI; } + /// Annotate memory instructions in the versioned loop with no-alias /// metadata based on the memchecks issued. /// @@ -115,6 +121,12 @@ /// loop may alias (memchecks failed). Loop *NonVersionedLoop; + /// The basic Block that stores the BranchInst to Versioned / NonVersioned + BasicBlock *RuntimeCheckBB; + + /// The branch instruction to Versioned / NonVersioned + BranchInst *RuntimeCheckBI; + /// This maps the instructions from VersionedLoop to their counterpart /// in NonVersionedLoop. ValueToValueMapTy VMap; diff --git a/llvm/lib/Transforms/Utils/LoopVersioning.cpp b/llvm/lib/Transforms/Utils/LoopVersioning.cpp --- a/llvm/lib/Transforms/Utils/LoopVersioning.cpp +++ b/llvm/lib/Transforms/Utils/LoopVersioning.cpp @@ -30,6 +30,9 @@ using namespace llvm; +#define LVER_OPTION "loop-versioning" +#define DEBUG_TYPE LVER_OPTION + static cl::opt AnnotateNoAlias("loop-version-annotate-no-alias", cl::init(true), cl::Hidden, @@ -84,8 +87,11 @@ } else RuntimeCheck = MemRuntimeCheck ? MemRuntimeCheck : SCEVRuntimeCheck; - assert(RuntimeCheck && "called even though we don't need " - "any runtime checks"); + if (!RuntimeCheck) { + LLVM_DEBUG(dbgs() << DEBUG_TYPE " No MemRuntimeCheck or SCEVRuntimeCheck found" + << ", set RuntimeCheck to False\n"); + RuntimeCheck = ConstantInt::getFalse(RuntimeCheckBB->getContext()); + } // Rename the block to make the IR more readable. RuntimeCheckBB->setName(VersionedLoop->getHeader()->getName() + @@ -109,8 +115,8 @@ // Insert the conditional branch based on the result of the memchecks. Instruction *OrigTerm = RuntimeCheckBB->getTerminator(); - BranchInst::Create(NonVersionedLoop->getLoopPreheader(), - VersionedLoop->getLoopPreheader(), RuntimeCheck, OrigTerm); + RuntimeCheckBI = BranchInst::Create(NonVersionedLoop->getLoopPreheader(), + VersionedLoop->getLoopPreheader(), RuntimeCheck, OrigTerm); OrigTerm->eraseFromParent(); // The loops merge in the original exit block. This is now dominated by the @@ -125,6 +131,9 @@ assert(NonVersionedLoop->isLoopSimplifyForm() && VersionedLoop->isLoopSimplifyForm() && "The versioned loops should be in simplify form."); + + // RuntimeCheckBB and RuntimeCheckBI is recorded + assert(RuntimeCheckBB && RuntimeCheckBI); } void LoopVersioning::addPHINodes( @@ -324,9 +333,6 @@ }; } -#define LVER_OPTION "loop-versioning" -#define DEBUG_TYPE LVER_OPTION - char LoopVersioningLegacyPass::ID; static const char LVer_name[] = "Loop Versioning";