[PATCH] D104679: [LoopUnrolling] Add flag to restrict the unroll with large loop size

Allen zhong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 21 19:01:54 PDT 2021


Allen created this revision.
Herald added subscribers: zzheng, hiraditya.
Allen requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Disable large loop unroll as it will exhaust the stack if without setting with ulimit -s unlimited
while getting loop count in recursion function computeBackedgeTakenCount etc.

related issue:
https://bugs.llvm.org/show_bug.cgi?id=49783


https://reviews.llvm.org/D104679

Files:
  llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp


Index: llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -122,6 +122,11 @@
     cl::desc(
         "Set the max unroll count for full unrolling, for testing purposes"));
 
+static cl::opt<unsigned> UnrollFullSizeThreshold(
+    "unroll-full-size-threshold", cl::init(1000), cl::Hidden,
+    cl::desc(
+        "Set the size threshold for full unrolling, for testing purposes"));
+
 static cl::opt<bool>
     UnrollAllowPartial("unroll-allow-partial", cl::Hidden,
                        cl::desc("Allows loops to be partially unrolled until "
@@ -1120,6 +1125,11 @@
     return LoopUnrollResult::Unmodified;
   }
 
+  if (LoopSize > UnrollFullSizeThreshold) {
+    LLVM_DEBUG(dbgs() << "  Not unrolling loop with as large loop size.\n");
+    return LoopUnrollResult::Unmodified;
+  }
+
   // Find the smallest exact trip count for any exit. This is an upper bound
   // on the loop trip count, but an exit at an earlier iteration is still
   // possible. An unroll by the smallest exact trip count guarantees that all


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104679.353524.patch
Type: text/x-patch
Size: 1186 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210622/ed48248c/attachment.bin>


More information about the llvm-commits mailing list