[PATCH] D40662: [PGO] Do not do counter promotion for loops without exit blocks ('infinite loops')

David Li via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 30 11:16:52 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL319462: [PGO] Skip counter promotion for infinite loops (authored by davidxl).

Changed prior to commit:
  https://reviews.llvm.org/D40662?vs=124967&id=124977#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40662

Files:
  llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/trunk/test/Transforms/PGOProfile/infinite_loop.ll


Index: llvm/trunk/test/Transforms/PGOProfile/infinite_loop.ll
===================================================================
--- llvm/trunk/test/Transforms/PGOProfile/infinite_loop.ll
+++ llvm/trunk/test/Transforms/PGOProfile/infinite_loop.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -instrprof -S -o - -do-counter-promotion=1  | FileCheck %s
+; CHECK: store
+
+ at __profn_foo = private constant [3 x i8] c"foo"
+
+define void @foo() {
+entry:
+  br label %while.body
+
+  while.body:                                       ; preds = %entry, %while.body
+    call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 14813359968, i32 1, i32 0)
+    call void (...) @bar() #2
+    br label %while.body
+}
+
+declare void @bar(...)
+
+declare void @llvm.instrprof.increment(i8*, i64, i32, i32) #0
+
+attributes #0 = { nounwind }
+
Index: llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -245,6 +245,9 @@
   }
 
   bool run(int64_t *NumPromoted) {
+    // Skip 'infinite' loops:
+    if (ExitBlocks.size() == 0)
+      return false;
     unsigned MaxProm = getMaxNumOfPromotionsInLoop(&L);
     if (MaxProm == 0)
       return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40662.124977.patch
Type: text/x-patch
Size: 1398 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171130/e733fe63/attachment.bin>


More information about the llvm-commits mailing list