[llvm] r319462 - [PGO] Skip counter promotion for infinite loops

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


Author: davidxl
Date: Thu Nov 30 11:16:25 2017
New Revision: 319462

URL: http://llvm.org/viewvc/llvm-project?rev=319462&view=rev
Log:
[PGO] Skip counter promotion for infinite loops

Differential Revision: http://reviews.llvm.org/D40662

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

Modified: llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp?rev=319462&r1=319461&r2=319462&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp Thu Nov 30 11:16:25 2017
@@ -245,6 +245,9 @@ public:
   }
 
   bool run(int64_t *NumPromoted) {
+    // Skip 'infinite' loops:
+    if (ExitBlocks.size() == 0)
+      return false;
     unsigned MaxProm = getMaxNumOfPromotionsInLoop(&L);
     if (MaxProm == 0)
       return false;

Added: llvm/trunk/test/Transforms/PGOProfile/infinite_loop.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/infinite_loop.ll?rev=319462&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/infinite_loop.ll (added)
+++ llvm/trunk/test/Transforms/PGOProfile/infinite_loop.ll Thu Nov 30 11:16:25 2017
@@ -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 }
+




More information about the llvm-commits mailing list