r199865 - CodeGen: Fix tracking of PGO counters for the logical or operator

Justin Bogner mail at justinbogner.com
Wed Jan 22 18:54:31 PST 2014


Author: bogner
Date: Wed Jan 22 20:54:30 2014
New Revision: 199865

URL: http://llvm.org/viewvc/llvm-project?rev=199865&view=rev
Log:
CodeGen: Fix tracking of PGO counters for the logical or operator

This adds tests for both logical or and for logical and, which was
already correct.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/test/CodeGen/Inputs/instr-profile.pgodata
    cfe/trunk/test/CodeGen/instr-profile.c

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=199865&r1=199864&r2=199865&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Wed Jan 22 20:54:30 2014
@@ -966,7 +966,7 @@ void CodeGenFunction::EmitBranchOnBoolEx
       // We have the count for entry to the RHS and for the whole expression
       // being true, so we can divy up True count between the short circuit and
       // the RHS.
-      uint64_t LHSCount = TrueCount - Cnt.getCount();
+      uint64_t LHSCount = Cnt.getParentCount() - Cnt.getCount();
       uint64_t RHSCount = TrueCount - LHSCount;
 
       ConditionalEvaluation eval(*this);

Modified: cfe/trunk/test/CodeGen/Inputs/instr-profile.pgodata
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/Inputs/instr-profile.pgodata?rev=199865&r1=199864&r2=199865&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/Inputs/instr-profile.pgodata (original)
+++ cfe/trunk/test/CodeGen/Inputs/instr-profile.pgodata Wed Jan 22 20:54:30 2014
@@ -116,6 +116,18 @@ big_switch 19
 2
 2
 
+boolean_operators 10
+1
+100
+0
+0
+34
+66
+17
+34
+33
+50
+
 no_usable_data 5
 1
 1

Modified: cfe/trunk/test/CodeGen/instr-profile.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/instr-profile.c?rev=199865&r1=199864&r2=199865&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/instr-profile.c (original)
+++ cfe/trunk/test/CodeGen/instr-profile.c Wed Jan 22 20:54:30 2014
@@ -14,6 +14,7 @@
 // PGOGEN: @[[JMC:__llvm_pgo_ctr[0-9]*]] = private global [30 x i64] zeroinitializer
 // PGOGEN: @[[SWC:__llvm_pgo_ctr[0-9]*]] = private global [21 x i64] zeroinitializer
 // PGOGEN: @[[BSC:__llvm_pgo_ctr[0-9]*]] = private global [19 x i64] zeroinitializer
+// PGOGEN: @[[BOC:__llvm_pgo_ctr[0-9]*]] = private global [10 x i64]  zeroinitializer
 // PGOGEN: @[[NOC:__llvm_pgo_ctr[0-9]*]] = private global [2 x i64]  zeroinitializer
 // PGOGEN: @[[MAC:__llvm_pgo_ctr[0-9]*]] = private global [1 x i64]  zeroinitializer
 
@@ -348,6 +349,39 @@ void big_switch() {
   // PGOUSE: ret void
 }
 
+// PGOGEN-LABEL: @boolean_operators()
+// PGOUSE-LABEL: @boolean_operators()
+// PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 0
+void boolean_operators() {
+  int v;
+  // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 1
+  // PGOUSE: br {{.*}} !prof ![[BO1:[0-9]+]]
+  for (int i = 0; i < 100; ++i) {
+    // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 4
+    // PGOUSE: br {{.*}} !prof ![[BO2:[0-9]+]]
+    v = i % 3 || i;
+
+    // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 5
+    // PGOUSE: br {{.*}} !prof ![[BO3:[0-9]+]]
+    v = i % 3 && i;
+
+    // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 7
+    // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 6
+    // PGOUSE: br {{.*}} !prof ![[BO4:[0-9]+]]
+    // PGOUSE: br {{.*}} !prof ![[BO5:[0-9]+]]
+    v = i % 3 || i % 2 || i;
+
+    // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 9
+    // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 8
+    // PGOUSE: br {{.*}} !prof ![[BO6:[0-9]+]]
+    // PGOUSE: br {{.*}} !prof ![[BO7:[0-9]+]]
+    v = i % 2 && i % 3 && i;
+  }
+
+  // PGOGEN-NOT: store {{.*}} @[BOC]],
+  // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
+}
+
 // PGOGEN-LABEL: @no_usable_data()
 // PGOUSE-LABEL: @no_usable_data()
 // PGOGEN: store {{.*}} @[[NOC]], i64 0, i64 0
@@ -416,6 +450,15 @@ void no_usable_data() {
 // PGOUSE-DAG: ![[BS10]] = metadata !{metadata !"branch_weights", i32 2, i32 1}
 // PGOUSE-DAG: ![[BS11]] = metadata !{metadata !"branch_weights", i32 3, i32 1}
 
+// PGOUSE-DAG: ![[BO1]] = metadata !{metadata !"branch_weights", i32 101, i32 2}
+// PGOUSE-DAG: ![[BO2]] = metadata !{metadata !"branch_weights", i32 67, i32 35}
+// PGOUSE-DAG: ![[BO3]] = metadata !{metadata !"branch_weights", i32 67, i32 35}
+// PGOUSE-DAG: ![[BO4]] = metadata !{metadata !"branch_weights", i32 67, i32 35}
+// PGOUSE-DAG: ![[BO5]] = metadata !{metadata !"branch_weights", i32 18, i32 18}
+// PGOUSE-DAG: ![[BO6]] = metadata !{metadata !"branch_weights", i32 51, i32 51}
+// PGOUSE-DAG: ![[BO7]] = metadata !{metadata !"branch_weights", i32 34, i32 18}
+
+
 int main(int argc, const char *argv[]) {
   simple_loops();
   conditionals();
@@ -423,6 +466,7 @@ int main(int argc, const char *argv[]) {
   jumps();
   switches();
   big_switch();
+  boolean_operators();
   no_usable_data();
   return 0;
 }





More information about the cfe-commits mailing list