[PATCH] D86844: [Loops] Introduces handling for the noprogress loop metadata.

Atmn Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 29 17:06:21 PDT 2020


atmnpatel created this revision.
atmnpatel added reviewers: jdoerfert, aaron.ballman, rsmith, rjmccall, aqjune, RalfJung.
Herald added subscribers: llvm-commits, danielkiss, hiraditya.
Herald added a project: LLVM.
atmnpatel requested review of this revision.

Introduces handling for the no progress loop metadata introduced in D86841 <https://reviews.llvm.org/D86841>. If a loop has `llvm.loop.noprogress` in its metadata, do not optimize it away even if it has no side effects. Hopefully, we can remove the MaxBackEdgeCount check now, because we now have a way to distinguish legal infinite loops without side effects and loops that may be infinite and do not have side effects. This would allow us to more aggressively optimize loops while remaining standard compliant for C/C++.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86844

Files:
  llvm/include/llvm/Transforms/Utils/LoopUtils.h
  llvm/lib/Transforms/Scalar/LoopDeletion.cpp
  llvm/lib/Transforms/Utils/LoopUtils.cpp


Index: llvm/lib/Transforms/Utils/LoopUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -63,6 +63,7 @@
 
 static const char *LLVMLoopDisableNonforced = "llvm.loop.disable_nonforced";
 static const char *LLVMLoopDisableLICM = "llvm.licm.disable";
+static const char *LLVMLoopNoProgress = "llvm.licm.noprogress";
 
 bool llvm::formDedicatedExitBlocks(Loop *L, DominatorTree *DT, LoopInfo *LI,
                                    MemorySSAUpdater *MSSAU,
@@ -404,6 +405,10 @@
   return getBooleanLoopAttribute(L, LLVMLoopDisableLICM);
 }
 
+bool llvm::hasNoProgress(const Loop *L) {
+  return getBooleanLoopAttribute(L, LLVMLoopNoProgress);
+}
+
 TransformationMode llvm::hasUnrollTransformation(Loop *L) {
   if (getBooleanLoopAttribute(L, "llvm.loop.unroll.disable"))
     return TM_SuppressedByUser;
Index: llvm/lib/Transforms/Scalar/LoopDeletion.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopDeletion.cpp
+++ llvm/lib/Transforms/Scalar/LoopDeletion.cpp
@@ -202,7 +202,12 @@
   // Don't remove loops for which we can't solve the trip count.
   // They could be infinite, in which case we'd be changing program behavior.
   const SCEV *S = SE.getConstantMaxBackedgeTakenCount(L);
-  if (isa<SCEVCouldNotCompute>(S)) {
+  if (hasNoProgress(L)) {
+    // Don't remove loops that are permitted to be no progress.
+    LLVM_DEBUG(dbgs() << "Loop is permitted to make no progress.\n");
+    return Changed ? LoopDeletionResult::Modified
+                   : LoopDeletionResult::Unmodified;
+  } else if (isa<SCEVCouldNotCompute>(S)) {
     LLVM_DEBUG(dbgs() << "Could not compute SCEV MaxBackedgeTakenCount.\n");
     return Changed ? LoopDeletionResult::Modified
                    : LoopDeletionResult::Unmodified;
Index: llvm/include/llvm/Transforms/Utils/LoopUtils.h
===================================================================
--- llvm/include/llvm/Transforms/Utils/LoopUtils.h
+++ llvm/include/llvm/Transforms/Utils/LoopUtils.h
@@ -227,6 +227,9 @@
 /// Look for the loop attribute that disables the LICM transformation heuristics.
 bool hasDisableLICMTransformsHint(const Loop *L);
 
+/// Look for the loop attribute that disables the Loop Deletion pass.
+bool hasNoProgress(const Loop *L);
+
 /// The mode sets how eager a transformation should be applied.
 enum TransformationMode {
   /// The pass can use heuristics to determine whether a transformation should


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86844.288819.patch
Type: text/x-patch
Size: 2553 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200830/bcceeafa/attachment.bin>


More information about the llvm-commits mailing list