[compiler-rt] r341977 - [gcov] Fix branch counters with switch statements (fix PR38821)

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 11 11:38:34 PDT 2018


Author: vedantk
Date: Tue Sep 11 11:38:34 2018
New Revision: 341977

URL: http://llvm.org/viewvc/llvm-project?rev=341977&view=rev
Log:
[gcov] Fix branch counters with switch statements (fix PR38821)

Right now, the counters are added in regards of the number of successors
for a given BasicBlock: it's good when we've only 1 or 2 successors (at
least with BranchInstr). But in the case of a switch statement, the
BasicBlock after switch has several predecessors and we need know from
which BB we're coming from.

So the idea is to revert what we're doing: add a PHINode in each block
which will select the counter according to the incoming BB.  They're
several pros for doing that:

- we fix the "switch" bug
- we remove the function call to "__llvm_gcov_indirect_counter_increment"
  and the lookup table stuff
- we replace by PHINodes, so the optimizer will probably makes a better
  job.

Patch by calixte!

Differential Revision: https://reviews.llvm.org/D51619

Modified:
    compiler-rt/trunk/test/profile/Inputs/instrprof-gcov-switch1.c.gcov
    compiler-rt/trunk/test/profile/Inputs/instrprof-gcov-switch2.c.gcov

Modified: compiler-rt/trunk/test/profile/Inputs/instrprof-gcov-switch1.c.gcov
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/Inputs/instrprof-gcov-switch1.c.gcov?rev=341977&r1=341976&r2=341977&view=diff
==============================================================================
--- compiler-rt/trunk/test/profile/Inputs/instrprof-gcov-switch1.c.gcov (original)
+++ compiler-rt/trunk/test/profile/Inputs/instrprof-gcov-switch1.c.gcov Tue Sep 11 11:38:34 2018
@@ -5,9 +5,9 @@
 // CHECK-NEXT:        -:    0:Programs:1
 // CHECK-NEXT:        -:    1:int main(void)
 // CHECK-NEXT:        -:    2:{
-// CHECK-NEXT:        2:    3:  int i = 22;
+// CHECK-NEXT:        1:    3:  int i = 22;
 // CHECK-NEXT:        -:    4:
-// CHECK-NEXT:        2:    5:  switch (i) {
+// CHECK-NEXT:        1:    5:  switch (i) {
 // CHECK-NEXT:        -:    6:    case 7:
 // CHECK-NEXT:    #####:    7:      break;
 // CHECK-NEXT:        -:    8:

Modified: compiler-rt/trunk/test/profile/Inputs/instrprof-gcov-switch2.c.gcov
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/Inputs/instrprof-gcov-switch2.c.gcov?rev=341977&r1=341976&r2=341977&view=diff
==============================================================================
--- compiler-rt/trunk/test/profile/Inputs/instrprof-gcov-switch2.c.gcov (original)
+++ compiler-rt/trunk/test/profile/Inputs/instrprof-gcov-switch2.c.gcov Tue Sep 11 11:38:34 2018
@@ -5,9 +5,9 @@
 // CHECK-NEXT:        -:    0:Programs:1
 // CHECK-NEXT:        -:    1:int main(void)
 // CHECK-NEXT:        -:    2:{
-// CHECK-NEXT:        3:    3:  int i = 22;
+// CHECK-NEXT:        1:    3:  int i = 22;
 // CHECK-NEXT:        -:    4:
-// CHECK-NEXT:        3:    5:  switch (i) {
+// CHECK-NEXT:        1:    5:  switch (i) {
 // CHECK-NEXT:        -:    6:    case 7:
 // CHECK-NEXT:    #####:    7:      break;
 // CHECK-NEXT:        -:    8:




More information about the llvm-commits mailing list