From e90895749d4b633799eac3385975cc21a6a9a2f5 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Thu, 23 Jan 2014 02:54:30 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199865 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenFunction.cpp | 2 +- test/CodeGen/Inputs/instr-profile.pgodata | 12 +++++++ test/CodeGen/instr-profile.c | 44 +++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index cffbca37bd..db629bf492 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -966,7 +966,7 @@ void CodeGenFunction::EmitBranchOnBoolExpr(const Expr *Cond, // 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); diff --git a/test/CodeGen/Inputs/instr-profile.pgodata b/test/CodeGen/Inputs/instr-profile.pgodata index ee4363aea7..578a6d24e5 100644 --- a/test/CodeGen/Inputs/instr-profile.pgodata +++ b/test/CodeGen/Inputs/instr-profile.pgodata @@ -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 diff --git a/test/CodeGen/instr-profile.c b/test/CodeGen/instr-profile.c index a5da9daba1..954c293932 100644 --- a/test/CodeGen/instr-profile.c +++ b/test/CodeGen/instr-profile.c @@ -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; } -- 2.40.0