[PATCH] D104631: [LoopVersioning] Allow versionLoop to create plain branch inst when no runtime check is specified

Yueh-Ting Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 10 08:24:57 PST 2021


eopXD updated this revision to Diff 393502.
eopXD added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104631

Files:
  llvm/include/llvm/Transforms/Utils/LoopVersioning.h
  llvm/lib/Transforms/Utils/LoopVersioning.cpp


Index: llvm/lib/Transforms/Utils/LoopVersioning.cpp
===================================================================
--- llvm/lib/Transforms/Utils/LoopVersioning.cpp
+++ 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<bool>
     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";
 
Index: llvm/include/llvm/Transforms/Utils/LoopVersioning.h
===================================================================
--- llvm/include/llvm/Transforms/Utils/LoopVersioning.h
+++ 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104631.393502.patch
Type: text/x-patch
Size: 3311 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211210/4a9478c3/attachment.bin>


More information about the llvm-commits mailing list