]> granicus.if.org Git - llvm/commitdiff
[PGO] Skip counter promotion for infinite loops
authorXinliang David Li <davidxl@google.com>
Thu, 30 Nov 2017 19:16:25 +0000 (19:16 +0000)
committerXinliang David Li <davidxl@google.com>
Thu, 30 Nov 2017 19:16:25 +0000 (19:16 +0000)
Differential Revision: http://reviews.llvm.org/D40662

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319462 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/InstrProfiling.cpp
test/Transforms/PGOProfile/infinite_loop.ll [new file with mode: 0644]

index db8fa897794793a9194ffc683e409d32eb228665..787afc32dfbf24a6563d9f1241a4260cbab04bfd 100644 (file)
@@ -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;
diff --git a/test/Transforms/PGOProfile/infinite_loop.ll b/test/Transforms/PGOProfile/infinite_loop.ll
new file mode 100644 (file)
index 0000000..68e9873
--- /dev/null
@@ -0,0 +1,21 @@
+; RUN: opt < %s -instrprof -S -o - -do-counter-promotion=1  | FileCheck %s
+; CHECK: store
+
+@__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 }
+