public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/2] gcov: test switch/break line counts
@ 2022-10-11 12:43 Jørgen Kvalsvik
  2022-10-11 12:43 ` [PATCH 2/2] gcov: test line count for label in then/else block Jørgen Kvalsvik
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Jørgen Kvalsvik @ 2022-10-11 12:43 UTC (permalink / raw)
  To: gcc-patches; +Cc: richard.guenther, mliska, Jørgen Kvalsvik

The coverage support will under some conditions decide to split edges to
accurately report coverage. By running the test suite with/without this
edge splitting a small diff shows up, addressed by this patch, which
should catch future regressions.

Removing the edge splitting:

    $ diff --git a/gcc/profile.cc b/gcc/profile.cc
    --- a/gcc/profile.cc
    +++ b/gcc/profile.cc
    @@ -1244,19 +1244,7 @@ branch_prob (bool thunk)
                    Don't do that when the locuses match, so
                    if (blah) goto something;
                    is not computed twice.  */
    -             if (last
    -                 && gimple_has_location (last)
    -                 && !RESERVED_LOCATION_P (e->goto_locus)
    -                 && !single_succ_p (bb)
    -                 && (LOCATION_FILE (e->goto_locus)
    -                     != LOCATION_FILE (gimple_location (last))
    -                     || (LOCATION_LINE (e->goto_locus)
    -                         != LOCATION_LINE (gimple_location (last)))))
    -               {
    -                 basic_block new_bb = split_edge (e);
    -                 edge ne = single_succ_edge (new_bb);
    -                 ne->goto_locus = e->goto_locus;
    -               }
    +
            if ((e->flags & (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL))
                    && e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
                    need_exit_edge = 1;

Assuming the .gcov files from make chec-gcc RUNTESTFLAGS=gcov.exp are
kept:

    $ diff -r no-split-edge with-split-edge | grep -C 2 -E "^[<>]\s\s"
    diff -r sans-split-edge/gcc/gcov-4.c.gcov with-split-edge/gcc/gcov-4.c.gcov
    228c228
    <         -:  224:        break;
    ---
    >         1:  224:        break;
    231c231
    <         -:  227:        break;
    ---
    >     #####:  227:        break;
    237c237
    <         -:  233:        break;
    ---
    >         2:  233:        break;

gcc/testsuite/ChangeLog:

	* g++.dg/gcov/gcov-1.C: Add line count check.
	* gcc.misc-tests/gcov-4.c: Likewise.
---
 gcc/testsuite/g++.dg/gcov/gcov-1.C    | 8 ++++----
 gcc/testsuite/gcc.misc-tests/gcov-4.c | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/g++.dg/gcov/gcov-1.C b/gcc/testsuite/g++.dg/gcov/gcov-1.C
index 9018b9a3a73..ee383b480a8 100644
--- a/gcc/testsuite/g++.dg/gcov/gcov-1.C
+++ b/gcc/testsuite/g++.dg/gcov/gcov-1.C
@@ -257,20 +257,20 @@ test_switch (int i, int j)
   switch (i)				/* count(5) */
 					/* branch(end) */
     {
-      case 1:
+      case 1:				/* count(1) */
         result = do_something (2);	/* count(1) */
-        break;
+        break;				/* count(1) */
       case 2:
         result = do_something (1024);
         break;
-      case 3:
+      case 3:				/* count(3) */
       case 4:
 					/* branch(67) */
         if (j == 2)			/* count(3) */
 					/* branch(end) */
           return do_something (4);	/* count(1) */
         result = do_something (8);	/* count(2) */
-        break;
+        break;				/* count(2) */
       default:
 	result = do_something (32);	/* count(1) */
 	switch_m++;			/* count(1) */
diff --git a/gcc/testsuite/gcc.misc-tests/gcov-4.c b/gcc/testsuite/gcc.misc-tests/gcov-4.c
index 9d8ab1c1097..498d299b66b 100644
--- a/gcc/testsuite/gcc.misc-tests/gcov-4.c
+++ b/gcc/testsuite/gcc.misc-tests/gcov-4.c
@@ -221,7 +221,7 @@ test_switch (int i, int j)
     {
       case 1:
         result = do_something (2);	/* count(1) */
-        break;
+        break;				/* count(1) */
       case 2:
         result = do_something (1024);
         break;
@@ -230,7 +230,7 @@ test_switch (int i, int j)
         if (j == 2)			/* count(3) */
           return do_something (4);	/* count(1) */
         result = do_something (8);	/* count(2) */
-        break;
+        break;				/* count(2) */
       default:
 	result = do_something (32);	/* count(1) */
 	switch_m++;			/* count(1) */
-- 
2.34.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/2] gcov: test line count for label in then/else block
  2022-10-11 12:43 [PATCH 1/2] gcov: test switch/break line counts Jørgen Kvalsvik
@ 2022-10-11 12:43 ` Jørgen Kvalsvik
  2022-10-13 11:40   ` Richard Biener
  2022-10-11 13:55 ` [PATCH 1/2] gcov: test switch/break line counts Michael Matz
  2022-10-13 11:39 ` Richard Biener
  2 siblings, 1 reply; 10+ messages in thread
From: Jørgen Kvalsvik @ 2022-10-11 12:43 UTC (permalink / raw)
  To: gcc-patches; +Cc: richard.guenther, mliska, Jørgen Kvalsvik

Add a test to catch regression in line counts for labels on top of
then/else blocks. Only the 'goto <label>' should contribute to the line
counter for the label, not the if.

gcc/testsuite/ChangeLog:

	* gcc.misc-tests/gcov-4.c:
---
 gcc/testsuite/gcc.misc-tests/gcov-4.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.misc-tests/gcov-4.c b/gcc/testsuite/gcc.misc-tests/gcov-4.c
index 498d299b66b..da7929ef7fc 100644
--- a/gcc/testsuite/gcc.misc-tests/gcov-4.c
+++ b/gcc/testsuite/gcc.misc-tests/gcov-4.c
@@ -110,6 +110,29 @@ lab2:
   return 8;				/* count(1) */
 }
 
+int
+test_goto3 (int i, int j)
+{
+    if (j) goto else_;		/* count(1) */
+
+top:
+    if (i)			/* count(1) */
+      {
+	i = do_something (i);
+      }
+    else
+      {
+else_:				/* count(1) */
+	j = do_something (j);	/* count(2) */
+	if (j)			/* count(2) */
+	  {
+	    j = 0;		/* count(1) */
+	    goto top;		/* count(1) */
+	  }
+      }
+    return 16;
+}
+
 void
 call_goto ()
 {
@@ -117,6 +140,7 @@ call_goto ()
   goto_val += test_goto1 (1);
   goto_val += test_goto2 (3);
   goto_val += test_goto2 (30);
+  goto_val += test_goto3 (0, 1);
 }
 
 /* Check nested if-then-else statements. */
@@ -260,7 +284,7 @@ main()
   call_unref ();
   if ((for_val1 != 12)
       || (for_val2 != 87)
-      || (goto_val != 15)
+      || (goto_val != 31)
       || (ifelse_val1 != 31)
       || (ifelse_val2 != 23)
       || (ifelse_val3 != 246)
-- 
2.34.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] gcov: test switch/break line counts
  2022-10-11 12:43 [PATCH 1/2] gcov: test switch/break line counts Jørgen Kvalsvik
  2022-10-11 12:43 ` [PATCH 2/2] gcov: test line count for label in then/else block Jørgen Kvalsvik
@ 2022-10-11 13:55 ` Michael Matz
  2022-10-11 13:57   ` Jørgen Kvalsvik
  2022-10-13 11:39 ` Richard Biener
  2 siblings, 1 reply; 10+ messages in thread
From: Michael Matz @ 2022-10-11 13:55 UTC (permalink / raw)
  To: Jørgen Kvalsvik; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1535 bytes --]

Hello,

On Tue, 11 Oct 2022, Jørgen Kvalsvik via Gcc-patches wrote:

> The coverage support will under some conditions decide to split edges to
> accurately report coverage. By running the test suite with/without this
> edge splitting a small diff shows up, addressed by this patch, which
> should catch future regressions.
> 
> Removing the edge splitting:
> 
>     $ diff --git a/gcc/profile.cc b/gcc/profile.cc
>     --- a/gcc/profile.cc
>     +++ b/gcc/profile.cc
>     @@ -1244,19 +1244,7 @@ branch_prob (bool thunk)
>                     Don't do that when the locuses match, so
>                     if (blah) goto something;
>                     is not computed twice.  */
>     -             if (last
>     -                 && gimple_has_location (last)
>     -                 && !RESERVED_LOCATION_P (e->goto_locus)
>     -                 && !single_succ_p (bb)
>     -                 && (LOCATION_FILE (e->goto_locus)
>     -                     != LOCATION_FILE (gimple_location (last))
>     -                     || (LOCATION_LINE (e->goto_locus)
>     -                         != LOCATION_LINE (gimple_location (last)))))
>     -               {
>     -                 basic_block new_bb = split_edge (e);
>     -                 edge ne = single_succ_edge (new_bb);
>     -                 ne->goto_locus = e->goto_locus;
>     -               }
>     +

Assuming this is correct (I really can't say) then the comment needs 
adjustments.  It specifically talks about this very code you remove.


Ciao,
Michael.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] gcov: test switch/break line counts
  2022-10-11 13:55 ` [PATCH 1/2] gcov: test switch/break line counts Michael Matz
@ 2022-10-11 13:57   ` Jørgen Kvalsvik
  2022-10-11 14:00     ` Michael Matz
  0 siblings, 1 reply; 10+ messages in thread
From: Jørgen Kvalsvik @ 2022-10-11 13:57 UTC (permalink / raw)
  To: Michael Matz; +Cc: gcc-patches

On 11/10/2022 15:55, Michael Matz wrote:
> Hello,
> 
> On Tue, 11 Oct 2022, Jørgen Kvalsvik via Gcc-patches wrote:
> 
>> The coverage support will under some conditions decide to split edges to
>> accurately report coverage. By running the test suite with/without this
>> edge splitting a small diff shows up, addressed by this patch, which
>> should catch future regressions.
>>
>> Removing the edge splitting:
>>
>>     $ diff --git a/gcc/profile.cc b/gcc/profile.cc
>>     --- a/gcc/profile.cc
>>     +++ b/gcc/profile.cc
>>     @@ -1244,19 +1244,7 @@ branch_prob (bool thunk)
>>                     Don't do that when the locuses match, so
>>                     if (blah) goto something;
>>                     is not computed twice.  */
>>     -             if (last
>>     -                 && gimple_has_location (last)
>>     -                 && !RESERVED_LOCATION_P (e->goto_locus)
>>     -                 && !single_succ_p (bb)
>>     -                 && (LOCATION_FILE (e->goto_locus)
>>     -                     != LOCATION_FILE (gimple_location (last))
>>     -                     || (LOCATION_LINE (e->goto_locus)
>>     -                         != LOCATION_LINE (gimple_location (last)))))
>>     -               {
>>     -                 basic_block new_bb = split_edge (e);
>>     -                 edge ne = single_succ_edge (new_bb);
>>     -                 ne->goto_locus = e->goto_locus;
>>     -               }
>>     +
> 
> Assuming this is correct (I really can't say) then the comment needs 
> adjustments.  It specifically talks about this very code you remove.
> 
> 
> Ciao,
> Michael.

Michael,

I apologise for the confusion. The diff there is not a part of the change itself
(note the indentation) but rather a way to reproduce, or at least understand,
the type of change that would trigger the new test error. If it is too confusing
I can re-write the commit message.

Thanks,
Jørgen

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] gcov: test switch/break line counts
  2022-10-11 13:57   ` Jørgen Kvalsvik
@ 2022-10-11 14:00     ` Michael Matz
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Matz @ 2022-10-11 14:00 UTC (permalink / raw)
  To: Jørgen Kvalsvik; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 280 bytes --]

Hello,

On Tue, 11 Oct 2022, Jørgen Kvalsvik wrote:

> I apologise for the confusion. The diff there is not a part of the 
> change itself (note the indentation) but rather a way to reproduce,

Ah!  Thanks, that explains it, sorry for adding confusion on top :-)


Ciao,
Michael.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] gcov: test switch/break line counts
  2022-10-11 12:43 [PATCH 1/2] gcov: test switch/break line counts Jørgen Kvalsvik
  2022-10-11 12:43 ` [PATCH 2/2] gcov: test line count for label in then/else block Jørgen Kvalsvik
  2022-10-11 13:55 ` [PATCH 1/2] gcov: test switch/break line counts Michael Matz
@ 2022-10-13 11:39 ` Richard Biener
  2022-10-14 10:09   ` Jørgen Kvalsvik
  2 siblings, 1 reply; 10+ messages in thread
From: Richard Biener @ 2022-10-13 11:39 UTC (permalink / raw)
  To: Jørgen Kvalsvik; +Cc: gcc-patches, mliska

On Tue, Oct 11, 2022 at 2:43 PM Jørgen Kvalsvik
<jorgen.kvalsvik@woven-planet.global> wrote:
>
> The coverage support will under some conditions decide to split edges to
> accurately report coverage. By running the test suite with/without this
> edge splitting a small diff shows up, addressed by this patch, which
> should catch future regressions.
>
> Removing the edge splitting:
>
>     $ diff --git a/gcc/profile.cc b/gcc/profile.cc
>     --- a/gcc/profile.cc
>     +++ b/gcc/profile.cc
>     @@ -1244,19 +1244,7 @@ branch_prob (bool thunk)
>                     Don't do that when the locuses match, so
>                     if (blah) goto something;
>                     is not computed twice.  */
>     -             if (last
>     -                 && gimple_has_location (last)
>     -                 && !RESERVED_LOCATION_P (e->goto_locus)
>     -                 && !single_succ_p (bb)
>     -                 && (LOCATION_FILE (e->goto_locus)
>     -                     != LOCATION_FILE (gimple_location (last))
>     -                     || (LOCATION_LINE (e->goto_locus)
>     -                         != LOCATION_LINE (gimple_location (last)))))
>     -               {
>     -                 basic_block new_bb = split_edge (e);
>     -                 edge ne = single_succ_edge (new_bb);
>     -                 ne->goto_locus = e->goto_locus;
>     -               }
>     +
>             if ((e->flags & (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL))
>                     && e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
>                     need_exit_edge = 1;
>
> Assuming the .gcov files from make chec-gcc RUNTESTFLAGS=gcov.exp are
> kept:
>
>     $ diff -r no-split-edge with-split-edge | grep -C 2 -E "^[<>]\s\s"
>     diff -r sans-split-edge/gcc/gcov-4.c.gcov with-split-edge/gcc/gcov-4.c.gcov
>     228c228
>     <         -:  224:        break;
>     ---
>     >         1:  224:        break;
>     231c231
>     <         -:  227:        break;
>     ---
>     >     #####:  227:        break;
>     237c237
>     <         -:  233:        break;
>     ---
>     >         2:  233:        break;
>
> gcc/testsuite/ChangeLog:

OK.

Thanks,
Richard.

>
>         * g++.dg/gcov/gcov-1.C: Add line count check.
>         * gcc.misc-tests/gcov-4.c: Likewise.
> ---
>  gcc/testsuite/g++.dg/gcov/gcov-1.C    | 8 ++++----
>  gcc/testsuite/gcc.misc-tests/gcov-4.c | 4 ++--
>  2 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/gcc/testsuite/g++.dg/gcov/gcov-1.C b/gcc/testsuite/g++.dg/gcov/gcov-1.C
> index 9018b9a3a73..ee383b480a8 100644
> --- a/gcc/testsuite/g++.dg/gcov/gcov-1.C
> +++ b/gcc/testsuite/g++.dg/gcov/gcov-1.C
> @@ -257,20 +257,20 @@ test_switch (int i, int j)
>    switch (i)                           /* count(5) */
>                                         /* branch(end) */
>      {
> -      case 1:
> +      case 1:                          /* count(1) */
>          result = do_something (2);     /* count(1) */
> -        break;
> +        break;                         /* count(1) */
>        case 2:
>          result = do_something (1024);
>          break;
> -      case 3:
> +      case 3:                          /* count(3) */
>        case 4:
>                                         /* branch(67) */
>          if (j == 2)                    /* count(3) */
>                                         /* branch(end) */
>            return do_something (4);     /* count(1) */
>          result = do_something (8);     /* count(2) */
> -        break;
> +        break;                         /* count(2) */
>        default:
>         result = do_something (32);     /* count(1) */
>         switch_m++;                     /* count(1) */
> diff --git a/gcc/testsuite/gcc.misc-tests/gcov-4.c b/gcc/testsuite/gcc.misc-tests/gcov-4.c
> index 9d8ab1c1097..498d299b66b 100644
> --- a/gcc/testsuite/gcc.misc-tests/gcov-4.c
> +++ b/gcc/testsuite/gcc.misc-tests/gcov-4.c
> @@ -221,7 +221,7 @@ test_switch (int i, int j)
>      {
>        case 1:
>          result = do_something (2);     /* count(1) */
> -        break;
> +        break;                         /* count(1) */
>        case 2:
>          result = do_something (1024);
>          break;
> @@ -230,7 +230,7 @@ test_switch (int i, int j)
>          if (j == 2)                    /* count(3) */
>            return do_something (4);     /* count(1) */
>          result = do_something (8);     /* count(2) */
> -        break;
> +        break;                         /* count(2) */
>        default:
>         result = do_something (32);     /* count(1) */
>         switch_m++;                     /* count(1) */
> --
> 2.34.0
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] gcov: test line count for label in then/else block
  2022-10-11 12:43 ` [PATCH 2/2] gcov: test line count for label in then/else block Jørgen Kvalsvik
@ 2022-10-13 11:40   ` Richard Biener
  0 siblings, 0 replies; 10+ messages in thread
From: Richard Biener @ 2022-10-13 11:40 UTC (permalink / raw)
  To: Jørgen Kvalsvik; +Cc: gcc-patches, mliska

On Tue, Oct 11, 2022 at 2:43 PM Jørgen Kvalsvik
<jorgen.kvalsvik@woven-planet.global> wrote:
>
> Add a test to catch regression in line counts for labels on top of
> then/else blocks. Only the 'goto <label>' should contribute to the line
> counter for the label, not the if.

OK.

> gcc/testsuite/ChangeLog:
>
>         * gcc.misc-tests/gcov-4.c:
> ---
>  gcc/testsuite/gcc.misc-tests/gcov-4.c | 26 +++++++++++++++++++++++++-
>  1 file changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/testsuite/gcc.misc-tests/gcov-4.c b/gcc/testsuite/gcc.misc-tests/gcov-4.c
> index 498d299b66b..da7929ef7fc 100644
> --- a/gcc/testsuite/gcc.misc-tests/gcov-4.c
> +++ b/gcc/testsuite/gcc.misc-tests/gcov-4.c
> @@ -110,6 +110,29 @@ lab2:
>    return 8;                            /* count(1) */
>  }
>
> +int
> +test_goto3 (int i, int j)
> +{
> +    if (j) goto else_;         /* count(1) */
> +
> +top:
> +    if (i)                     /* count(1) */
> +      {
> +       i = do_something (i);
> +      }
> +    else
> +      {
> +else_:                         /* count(1) */
> +       j = do_something (j);   /* count(2) */
> +       if (j)                  /* count(2) */
> +         {
> +           j = 0;              /* count(1) */
> +           goto top;           /* count(1) */
> +         }
> +      }
> +    return 16;
> +}
> +
>  void
>  call_goto ()
>  {
> @@ -117,6 +140,7 @@ call_goto ()
>    goto_val += test_goto1 (1);
>    goto_val += test_goto2 (3);
>    goto_val += test_goto2 (30);
> +  goto_val += test_goto3 (0, 1);
>  }
>
>  /* Check nested if-then-else statements. */
> @@ -260,7 +284,7 @@ main()
>    call_unref ();
>    if ((for_val1 != 12)
>        || (for_val2 != 87)
> -      || (goto_val != 15)
> +      || (goto_val != 31)
>        || (ifelse_val1 != 31)
>        || (ifelse_val2 != 23)
>        || (ifelse_val3 != 246)
> --
> 2.34.0
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] gcov: test switch/break line counts
  2022-10-13 11:39 ` Richard Biener
@ 2022-10-14 10:09   ` Jørgen Kvalsvik
  0 siblings, 0 replies; 10+ messages in thread
From: Jørgen Kvalsvik @ 2022-10-14 10:09 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches, mliska

On 13/10/2022 13:39, Richard Biener wrote:
> On Tue, Oct 11, 2022 at 2:43 PM Jørgen Kvalsvik
> <jorgen.kvalsvik@woven-planet.global> wrote:
>>
>> The coverage support will under some conditions decide to split edges to
>> accurately report coverage. By running the test suite with/without this
>> edge splitting a small diff shows up, addressed by this patch, which
>> should catch future regressions.
>>
>> Removing the edge splitting:
>>
>>     $ diff --git a/gcc/profile.cc b/gcc/profile.cc
>>     --- a/gcc/profile.cc
>>     +++ b/gcc/profile.cc
>>     @@ -1244,19 +1244,7 @@ branch_prob (bool thunk)
>>                     Don't do that when the locuses match, so
>>                     if (blah) goto something;
>>                     is not computed twice.  */
>>     -             if (last
>>     -                 && gimple_has_location (last)
>>     -                 && !RESERVED_LOCATION_P (e->goto_locus)
>>     -                 && !single_succ_p (bb)
>>     -                 && (LOCATION_FILE (e->goto_locus)
>>     -                     != LOCATION_FILE (gimple_location (last))
>>     -                     || (LOCATION_LINE (e->goto_locus)
>>     -                         != LOCATION_LINE (gimple_location (last)))))
>>     -               {
>>     -                 basic_block new_bb = split_edge (e);
>>     -                 edge ne = single_succ_edge (new_bb);
>>     -                 ne->goto_locus = e->goto_locus;
>>     -               }
>>     +
>>             if ((e->flags & (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL))
>>                     && e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
>>                     need_exit_edge = 1;
>>
>> Assuming the .gcov files from make chec-gcc RUNTESTFLAGS=gcov.exp are
>> kept:
>>
>>     $ diff -r no-split-edge with-split-edge | grep -C 2 -E "^[<>]\s\s"
>>     diff -r sans-split-edge/gcc/gcov-4.c.gcov with-split-edge/gcc/gcov-4.c.gcov
>>     228c228
>>     <         -:  224:        break;
>>     ---
>>     >         1:  224:        break;
>>     231c231
>>     <         -:  227:        break;
>>     ---
>>     >     #####:  227:        break;
>>     237c237
>>     <         -:  233:        break;
>>     ---
>>     >         2:  233:        break;
>>
>> gcc/testsuite/ChangeLog:
> 
> OK.
> 
> Thanks,
> Richard.
> 
>>
>>         * g++.dg/gcov/gcov-1.C: Add line count check.
>>         * gcc.misc-tests/gcov-4.c: Likewise.
>> ---
>>  gcc/testsuite/g++.dg/gcov/gcov-1.C    | 8 ++++----
>>  gcc/testsuite/gcc.misc-tests/gcov-4.c | 4 ++--
>>  2 files changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/gcc/testsuite/g++.dg/gcov/gcov-1.C b/gcc/testsuite/g++.dg/gcov/gcov-1.C
>> index 9018b9a3a73..ee383b480a8 100644
>> --- a/gcc/testsuite/g++.dg/gcov/gcov-1.C
>> +++ b/gcc/testsuite/g++.dg/gcov/gcov-1.C
>> @@ -257,20 +257,20 @@ test_switch (int i, int j)
>>    switch (i)                           /* count(5) */
>>                                         /* branch(end) */
>>      {
>> -      case 1:
>> +      case 1:                          /* count(1) */
>>          result = do_something (2);     /* count(1) */
>> -        break;
>> +        break;                         /* count(1) */
>>        case 2:
>>          result = do_something (1024);
>>          break;
>> -      case 3:
>> +      case 3:                          /* count(3) */
>>        case 4:
>>                                         /* branch(67) */
>>          if (j == 2)                    /* count(3) */
>>                                         /* branch(end) */
>>            return do_something (4);     /* count(1) */
>>          result = do_something (8);     /* count(2) */
>> -        break;
>> +        break;                         /* count(2) */
>>        default:
>>         result = do_something (32);     /* count(1) */
>>         switch_m++;                     /* count(1) */
>> diff --git a/gcc/testsuite/gcc.misc-tests/gcov-4.c b/gcc/testsuite/gcc.misc-tests/gcov-4.c
>> index 9d8ab1c1097..498d299b66b 100644
>> --- a/gcc/testsuite/gcc.misc-tests/gcov-4.c
>> +++ b/gcc/testsuite/gcc.misc-tests/gcov-4.c
>> @@ -221,7 +221,7 @@ test_switch (int i, int j)
>>      {
>>        case 1:
>>          result = do_something (2);     /* count(1) */
>> -        break;
>> +        break;                         /* count(1) */
>>        case 2:
>>          result = do_something (1024);
>>          break;
>> @@ -230,7 +230,7 @@ test_switch (int i, int j)
>>          if (j == 2)                    /* count(3) */
>>            return do_something (4);     /* count(1) */
>>          result = do_something (8);     /* count(2) */
>> -        break;
>> +        break;                         /* count(2) */
>>        default:
>>         result = do_something (32);     /* count(1) */
>>         switch_m++;                     /* count(1) */
>> --
>> 2.34.0
>>

Thank you, I've installed the patches.

I noticed that the inclusion of diffs in the message works fine with git
generally, but could be picked up on by git format-patch && git am < patch. I
hope that does not end up causing too many problems (last time, promise!)

Thanks,
Jørgen

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] gcov: test switch/break line counts
  2022-10-05 12:04 ` [PATCH 1/2] gcov: test switch/break line counts Jørgen Kvalsvik
@ 2022-10-05 12:27   ` Martin Liška
  0 siblings, 0 replies; 10+ messages in thread
From: Martin Liška @ 2022-10-05 12:27 UTC (permalink / raw)
  To: Jørgen Kvalsvik, gcc-patches

On 10/5/22 14:04, Jørgen Kvalsvik via Gcc-patches wrote:
> The coverage support will under some conditions decide to split edges to
> accurately report coverage. By running the test suite with/without this
> edge splitting a small diff shows up, addressed by this patch, which
> should catch future regressions.

Thanks for the patch, it's OK (please apply it).

Martin

> 
> Removing the edge splitting:
> 
> diff --git a/gcc/profile.cc b/gcc/profile.cc
> --- a/gcc/profile.cc
> +++ b/gcc/profile.cc
> @@ -1244,19 +1244,7 @@ branch_prob (bool thunk)
>                 Don't do that when the locuses match, so
>                 if (blah) goto something;
>                 is not computed twice.  */
> -             if (last
> -                 && gimple_has_location (last)
> -                 && !RESERVED_LOCATION_P (e->goto_locus)
> -                 && !single_succ_p (bb)
> -                 && (LOCATION_FILE (e->goto_locus)
> -                     != LOCATION_FILE (gimple_location (last))
> -                     || (LOCATION_LINE (e->goto_locus)
> -                         != LOCATION_LINE (gimple_location (last)))))
> -               {
> -                 basic_block new_bb = split_edge (e);
> -                 edge ne = single_succ_edge (new_bb);
> -                 ne->goto_locus = e->goto_locus;
> -               }
> +
>         if ((e->flags & (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL))
>                 && e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
>                 need_exit_edge = 1;
> 
> Assuming the .gcov files from make chec-gcc RUNTESTFLAGS=gcov.exp are
> kept:
> 
> $ diff -r no-split-edge with-split-edge | grep -C 2 -E "^[<>]\s\s"
> diff -r sans-split-edge/gcc/gcov-4.c.gcov with-split-edge/gcc/gcov-4.c.gcov
>    228c228
>    <         -:  224:        break;
>    ---
>    >         1:  224:        break;
>    231c231
>    <         -:  227:        break;
>    ---
>    >     #####:  227:        break;
>    237c237
>    <         -:  233:        break;
>    ---
>    >         2:  233:        break;
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/gcov/gcov-1.C: Add line count check.
> 	* gcc.misc-tests/gcov-4.c: Likewise.
> ---
>  gcc/testsuite/g++.dg/gcov/gcov-1.C    | 8 ++++----
>  gcc/testsuite/gcc.misc-tests/gcov-4.c | 4 ++--
>  2 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/gcc/testsuite/g++.dg/gcov/gcov-1.C b/gcc/testsuite/g++.dg/gcov/gcov-1.C
> index 9018b9a3a73..ee383b480a8 100644
> --- a/gcc/testsuite/g++.dg/gcov/gcov-1.C
> +++ b/gcc/testsuite/g++.dg/gcov/gcov-1.C
> @@ -257,20 +257,20 @@ test_switch (int i, int j)
>    switch (i)				/* count(5) */
>  					/* branch(end) */
>      {
> -      case 1:
> +      case 1:				/* count(1) */
>          result = do_something (2);	/* count(1) */
> -        break;
> +        break;				/* count(1) */
>        case 2:
>          result = do_something (1024);
>          break;
> -      case 3:
> +      case 3:				/* count(3) */
>        case 4:
>  					/* branch(67) */
>          if (j == 2)			/* count(3) */
>  					/* branch(end) */
>            return do_something (4);	/* count(1) */
>          result = do_something (8);	/* count(2) */
> -        break;
> +        break;				/* count(2) */
>        default:
>  	result = do_something (32);	/* count(1) */
>  	switch_m++;			/* count(1) */
> diff --git a/gcc/testsuite/gcc.misc-tests/gcov-4.c b/gcc/testsuite/gcc.misc-tests/gcov-4.c
> index 9d8ab1c1097..498d299b66b 100644
> --- a/gcc/testsuite/gcc.misc-tests/gcov-4.c
> +++ b/gcc/testsuite/gcc.misc-tests/gcov-4.c
> @@ -221,7 +221,7 @@ test_switch (int i, int j)
>      {
>        case 1:
>          result = do_something (2);	/* count(1) */
> -        break;
> +        break;				/* count(1) */
>        case 2:
>          result = do_something (1024);
>          break;
> @@ -230,7 +230,7 @@ test_switch (int i, int j)
>          if (j == 2)			/* count(3) */
>            return do_something (4);	/* count(1) */
>          result = do_something (8);	/* count(2) */
> -        break;
> +        break;				/* count(2) */
>        default:
>  	result = do_something (32);	/* count(1) */
>  	switch_m++;			/* count(1) */


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/2] gcov: test switch/break line counts
  2022-10-05 12:04 [PATCH 0/2] gcov: Split when edge locus differ from dest bb Jørgen Kvalsvik
@ 2022-10-05 12:04 ` Jørgen Kvalsvik
  2022-10-05 12:27   ` Martin Liška
  0 siblings, 1 reply; 10+ messages in thread
From: Jørgen Kvalsvik @ 2022-10-05 12:04 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jørgen Kvalsvik

The coverage support will under some conditions decide to split edges to
accurately report coverage. By running the test suite with/without this
edge splitting a small diff shows up, addressed by this patch, which
should catch future regressions.

Removing the edge splitting:

diff --git a/gcc/profile.cc b/gcc/profile.cc
--- a/gcc/profile.cc
+++ b/gcc/profile.cc
@@ -1244,19 +1244,7 @@ branch_prob (bool thunk)
                Don't do that when the locuses match, so
                if (blah) goto something;
                is not computed twice.  */
-             if (last
-                 && gimple_has_location (last)
-                 && !RESERVED_LOCATION_P (e->goto_locus)
-                 && !single_succ_p (bb)
-                 && (LOCATION_FILE (e->goto_locus)
-                     != LOCATION_FILE (gimple_location (last))
-                     || (LOCATION_LINE (e->goto_locus)
-                         != LOCATION_LINE (gimple_location (last)))))
-               {
-                 basic_block new_bb = split_edge (e);
-                 edge ne = single_succ_edge (new_bb);
-                 ne->goto_locus = e->goto_locus;
-               }
+
        if ((e->flags & (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL))
                && e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
                need_exit_edge = 1;

Assuming the .gcov files from make chec-gcc RUNTESTFLAGS=gcov.exp are
kept:

$ diff -r no-split-edge with-split-edge | grep -C 2 -E "^[<>]\s\s"
diff -r sans-split-edge/gcc/gcov-4.c.gcov with-split-edge/gcc/gcov-4.c.gcov
   228c228
   <         -:  224:        break;
   ---
   >         1:  224:        break;
   231c231
   <         -:  227:        break;
   ---
   >     #####:  227:        break;
   237c237
   <         -:  233:        break;
   ---
   >         2:  233:        break;

gcc/testsuite/ChangeLog:

	* g++.dg/gcov/gcov-1.C: Add line count check.
	* gcc.misc-tests/gcov-4.c: Likewise.
---
 gcc/testsuite/g++.dg/gcov/gcov-1.C    | 8 ++++----
 gcc/testsuite/gcc.misc-tests/gcov-4.c | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/g++.dg/gcov/gcov-1.C b/gcc/testsuite/g++.dg/gcov/gcov-1.C
index 9018b9a3a73..ee383b480a8 100644
--- a/gcc/testsuite/g++.dg/gcov/gcov-1.C
+++ b/gcc/testsuite/g++.dg/gcov/gcov-1.C
@@ -257,20 +257,20 @@ test_switch (int i, int j)
   switch (i)				/* count(5) */
 					/* branch(end) */
     {
-      case 1:
+      case 1:				/* count(1) */
         result = do_something (2);	/* count(1) */
-        break;
+        break;				/* count(1) */
       case 2:
         result = do_something (1024);
         break;
-      case 3:
+      case 3:				/* count(3) */
       case 4:
 					/* branch(67) */
         if (j == 2)			/* count(3) */
 					/* branch(end) */
           return do_something (4);	/* count(1) */
         result = do_something (8);	/* count(2) */
-        break;
+        break;				/* count(2) */
       default:
 	result = do_something (32);	/* count(1) */
 	switch_m++;			/* count(1) */
diff --git a/gcc/testsuite/gcc.misc-tests/gcov-4.c b/gcc/testsuite/gcc.misc-tests/gcov-4.c
index 9d8ab1c1097..498d299b66b 100644
--- a/gcc/testsuite/gcc.misc-tests/gcov-4.c
+++ b/gcc/testsuite/gcc.misc-tests/gcov-4.c
@@ -221,7 +221,7 @@ test_switch (int i, int j)
     {
       case 1:
         result = do_something (2);	/* count(1) */
-        break;
+        break;				/* count(1) */
       case 2:
         result = do_something (1024);
         break;
@@ -230,7 +230,7 @@ test_switch (int i, int j)
         if (j == 2)			/* count(3) */
           return do_something (4);	/* count(1) */
         result = do_something (8);	/* count(2) */
-        break;
+        break;				/* count(2) */
       default:
 	result = do_something (32);	/* count(1) */
 	switch_m++;			/* count(1) */
-- 
2.30.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-10-14 10:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-11 12:43 [PATCH 1/2] gcov: test switch/break line counts Jørgen Kvalsvik
2022-10-11 12:43 ` [PATCH 2/2] gcov: test line count for label in then/else block Jørgen Kvalsvik
2022-10-13 11:40   ` Richard Biener
2022-10-11 13:55 ` [PATCH 1/2] gcov: test switch/break line counts Michael Matz
2022-10-11 13:57   ` Jørgen Kvalsvik
2022-10-11 14:00     ` Michael Matz
2022-10-13 11:39 ` Richard Biener
2022-10-14 10:09   ` Jørgen Kvalsvik
  -- strict thread matches above, loose matches on Subject: below --
2022-10-05 12:04 [PATCH 0/2] gcov: Split when edge locus differ from dest bb Jørgen Kvalsvik
2022-10-05 12:04 ` [PATCH 1/2] gcov: test switch/break line counts Jørgen Kvalsvik
2022-10-05 12:27   ` Martin Liška

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).