[PATCH] D104631: [LoopVersioning] add function to create versioned loop with plain runtime check

Yueh-Ting Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 21 03:41:51 PDT 2021


eopXD created this revision.
Herald added a subscriber: hiraditya.
eopXD requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

After this function call, the LLVM IR would look the following

  if (true)
    /* NonVersionedLoop */
  else
    /* VersionedLoop */


Repository:
  rG LLVM Github Monorepo

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
@@ -48,7 +48,8 @@
 }
 
 void LoopVersioning::versionLoop(
-    const SmallVectorImpl<Instruction *> &DefsUsedOutside) {
+    const SmallVectorImpl<Instruction *> &DefsUsedOutside,
+    bool AddPlainRuntimeCheck) {
   assert(VersionedLoop->isLoopSimplifyForm() &&
          "Loop is not in loop-simplify form");
 
@@ -85,8 +86,13 @@
   } else
     RuntimeCheck = MemRuntimeCheck ? MemRuntimeCheck : SCEVRuntimeCheck;
 
-  assert(RuntimeCheck && "called even though we don't need "
-                         "any runtime checks");
+  if (AddPlainRuntimeCheck) {
+    RuntimeCheck = ConstantInt::getTrue(RuntimeCheckBB->getContext());
+  }
+
+  assert(RuntimeCheck && "called versionLoop even though we don't need "
+                         "any runtime checks"
+                         "use versionLoopWithPlainRuntimeCheck instead");
 
   // Rename the block to make the IR more readable.
   RuntimeCheckBB->setName(VersionedLoop->getHeader()->getName() +
Index: llvm/include/llvm/Transforms/Utils/LoopVersioning.h
===================================================================
--- llvm/include/llvm/Transforms/Utils/LoopVersioning.h
+++ llvm/include/llvm/Transforms/Utils/LoopVersioning.h
@@ -60,11 +60,24 @@
   ///        analyze L
   ///        if versioning is necessary version L
   ///        transform L
-  void versionLoop() { versionLoop(findDefsUsedOutsideOfLoop(VersionedLoop)); }
+  void versionLoop() { versionLoop(findDefsUsedOutsideOfLoop(VersionedLoop), false); }
+
+  /// Clone loops with runtime check. After this function call, the LLVM IR
+  /// would look like the following:
+  ///
+  /// if (true) {
+  ///   NonVersionedLoop
+  /// } else {
+  ///   VersionedLoop
+  /// }
+  void versionLoopWithPlainRuntimeCheck() {
+    versionLoop(findDefsUsedOutsideOfLoop(VersionedLoop), true);
+  }
 
   /// Same but if the client has already precomputed the set of values
   /// used outside the loop, this API will allows passing that.
-  void versionLoop(const SmallVectorImpl<Instruction *> &DefsUsedOutside);
+  void versionLoop(const SmallVectorImpl<Instruction *> &DefsUsedOutside,
+                   bool AddPlainRuntimeCheck = false);
 
   /// Returns the versioned loop.  Control flows here if pointers in the
   /// loop don't alias (i.e. all memchecks passed).  (This loop is actually the


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104631.353325.patch
Type: text/x-patch
Size: 2540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210621/5a8dd5d3/attachment.bin>


More information about the llvm-commits mailing list