[PATCH] D44809: [PGO] Fix branch probability remarks assert

Rong Xu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 27 11:58:47 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL328653: [PGO] Fix branch probability remarks assert (authored by xur, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44809?vs=139520&id=139965#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44809

Files:
  llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/trunk/test/Transforms/PGOProfile/Inputs/large_count_remarks.proftext
  llvm/trunk/test/Transforms/PGOProfile/large_count_remarks.ll


Index: llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -224,8 +224,8 @@
     EmitBranchProbability("pgo-emit-branch-prob", cl::init(false), cl::Hidden,
                           cl::desc("When this option is on, the annotated "
                                    "branch probability will be emitted as "
-                                   " optimization remarks: -Rpass-analysis="
-                                   "pgo-instr-use"));
+                                   "optimization remarks: -{Rpass|"
+                                   "pass-remarks}=pgo-instrumentation"));
 
 // Command line option to turn on CFG dot dump after profile annotation.
 // Defined in Analysis/BlockFrequencyInfo.cpp:  -pgo-view-counts
@@ -1595,13 +1595,15 @@
     if (BrCondStr.empty())
       return;
 
-    unsigned WSum =
-        std::accumulate(Weights.begin(), Weights.end(), 0,
-                        [](unsigned w1, unsigned w2) { return w1 + w2; });
+    uint64_t WSum =
+        std::accumulate(Weights.begin(), Weights.end(), (uint64_t)0,
+                        [](uint64_t w1, uint64_t w2) { return w1 + w2; });
     uint64_t TotalCount =
-        std::accumulate(EdgeCounts.begin(), EdgeCounts.end(), 0,
+        std::accumulate(EdgeCounts.begin(), EdgeCounts.end(), (uint64_t)0,
                         [](uint64_t c1, uint64_t c2) { return c1 + c2; });
-    BranchProbability BP(Weights[0], WSum);
+    Scale = calculateCountScale(WSum);
+    BranchProbability BP(scaleBranchCount(Weights[0], Scale),
+                         scaleBranchCount(WSum, Scale));
     std::string BranchProbStr;
     raw_string_ostream OS(BranchProbStr);
     OS << BP;
Index: llvm/trunk/test/Transforms/PGOProfile/Inputs/large_count_remarks.proftext
===================================================================
--- llvm/trunk/test/Transforms/PGOProfile/Inputs/large_count_remarks.proftext
+++ llvm/trunk/test/Transforms/PGOProfile/Inputs/large_count_remarks.proftext
@@ -0,0 +1,8 @@
+# :ir is the flag to indicate this is IR level profile.
+:ir
+test
+25571299074
+2
+40000000000
+20000000000
+
Index: llvm/trunk/test/Transforms/PGOProfile/large_count_remarks.ll
===================================================================
--- llvm/trunk/test/Transforms/PGOProfile/large_count_remarks.ll
+++ llvm/trunk/test/Transforms/PGOProfile/large_count_remarks.ll
@@ -0,0 +1,22 @@
+; RUN: llvm-profdata merge %S/Inputs/large_count_remarks.proftext -o %t.profdata
+; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -pass-remarks=pgo-instrumentation -pgo-emit-branch-prob -S 2>&1| FileCheck %s --check-prefix=ANALYSIS
+; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -pass-remarks=pgo-instrumentation -pgo-emit-branch-prob -S 2>&1| FileCheck %s --check-prefix=ANALYSIS
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @test(i32 %i) {
+entry:
+  %cmp = icmp sgt i32 %i, 0
+  br i1 %cmp, label %if.then, label %if.end
+
+if.then:
+  %add = add nsw i32 %i, 2
+  br label %if.end
+
+if.end:
+  %retv = phi i32 [ %add, %if.then ], [ %i, %entry ]
+  ret i32 %retv
+}
+
+; ANALYSIS:remark: <unknown>:0:0: sgt_i32_Zero {{.*}}50.00% (total count : 40000000000)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44809.139965.patch
Type: text/x-patch
Size: 3483 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180327/654f7793/attachment.bin>


More information about the llvm-commits mailing list