[gcc r16-6348] AutoFDO: Update bootstrap gcov_version to 3 and add testcases

Dhruv Chawla dhruvc@gcc.gnu.org
Tue Dec 23 05:25:46 GMT 2025


https://gcc.gnu.org/g:4dfa48077e3892c652517cd5711915f4aa6875ef

commit r16-6348-g4dfa48077e3892c652517cd5711915f4aa6875ef
Author: Dhruv Chawla <dhruvc@nvidia.com>
Date:   Wed Oct 15 22:17:26 2025 -0700

    AutoFDO: Update bootstrap gcov_version to 3 and add testcases
    
    Signed-off-by: Dhruv Chawla <dhruvc@nvidia.com>
    
    gcc/c/ChangeLog:
    
            * Make-lang.in: Bump GCOV version to 3.
    
    gcc/cp/ChangeLog:
    
            * Make-lang.in: Bump GCOV version to 3.
    
    gcc/lto/ChangeLog:
    
            * Make-lang.in: Bump GCOV version to 3.
    
    gcc/testsuite/ChangeLog:
    
            * lib/profopt.exp: Bump GCOV version to 3.
            * gcc.dg/tree-prof/afdo-lto_priv-basic-0.c: New test.
            * gcc.dg/tree-prof/afdo-lto_priv-basic-1.c: Likewise.
            * gcc.dg/tree-prof/afdo-lto_priv-header-0.c: Likewise.
            * gcc.dg/tree-prof/afdo-lto_priv-header-0.h: Likewise.
            * gcc.dg/tree-prof/afdo-lto_priv-header-1.c: Likewise.
            * gcc.dg/tree-prof/afdo-lto_priv-header-1.h: Likewise.

Diff:
---
 gcc/c/Make-lang.in                                 |  4 +-
 gcc/cp/Make-lang.in                                |  4 +-
 gcc/lto/Make-lang.in                               |  4 +-
 .../gcc.dg/tree-prof/afdo-lto_priv-basic-0.c       | 47 ++++++++++++++++++++++
 .../gcc.dg/tree-prof/afdo-lto_priv-basic-1.c       | 20 +++++++++
 .../gcc.dg/tree-prof/afdo-lto_priv-header-0.c      | 47 ++++++++++++++++++++++
 .../gcc.dg/tree-prof/afdo-lto_priv-header-0.h      |  3 ++
 .../gcc.dg/tree-prof/afdo-lto_priv-header-1.c      | 18 +++++++++
 .../gcc.dg/tree-prof/afdo-lto_priv-header-1.h      |  3 ++
 gcc/testsuite/lib/profopt.exp                      |  2 +-
 10 files changed, 145 insertions(+), 7 deletions(-)

diff --git a/gcc/c/Make-lang.in b/gcc/c/Make-lang.in
index f09fc99467b9..95a7dad83504 100644
--- a/gcc/c/Make-lang.in
+++ b/gcc/c/Make-lang.in
@@ -102,7 +102,7 @@ create_fdas_for_cc1: ../stage1-gcc/cc1$(exeext) ../prev-gcc/$(PERF_DATA)
 	  echo $$perf_path; \
 	  if [ -f $$perf_path ]; then \
 	    profile_name=cc1_$$component_in_prev.fda; \
-	    $(CREATE_GCOV) -binary ../stage1-gcc/cc1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 2 || exit 1; \
+	    $(CREATE_GCOV) -binary ../stage1-gcc/cc1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 3 || exit 1; \
 	  fi; \
 	done;
 
@@ -112,7 +112,7 @@ create_fdas_for_cc1: ../stage1-gcc/cc1$(exeext) ../prev-gcc/$(PERF_DATA)
 	  echo $$perf_path; \
 	  if [ -f $$perf_path ]; then \
 	    profile_name=cc1_$$component_in_prev_target.fda; \
-	    $(CREATE_GCOV) -binary ../prev-gcc/cc1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 2 || exit 1; \
+	    $(CREATE_GCOV) -binary ../prev-gcc/cc1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 3 || exit 1; \
 	  fi; \
 	done;
 
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index 70cfe2b16636..20ae96c18ed2 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -201,7 +201,7 @@ create_fdas_for_cc1plus: ../stage1-gcc/cc1plus$(exeext) ../prev-gcc/$(PERF_DATA)
 	  echo $$perf_path; \
 	  if [ -f $$perf_path ]; then \
 	    profile_name=cc1plus_$$component_in_prev.fda; \
-	    $(CREATE_GCOV) -binary ../stage1-gcc/cc1plus$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 2 || exit 1; \
+	    $(CREATE_GCOV) -binary ../stage1-gcc/cc1plus$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 3 || exit 1; \
 	  fi; \
 	done;
 
@@ -211,7 +211,7 @@ create_fdas_for_cc1plus: ../stage1-gcc/cc1plus$(exeext) ../prev-gcc/$(PERF_DATA)
 	  echo $$perf_path; \
 	  if [ -f $$perf_path ]; then \
 	    profile_name=cc1plus_$$component_in_prev_target.fda; \
-	    $(CREATE_GCOV) -binary ../prev-gcc/cc1plus$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 2 || exit 1; \
+	    $(CREATE_GCOV) -binary ../prev-gcc/cc1plus$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 3 || exit 1; \
 	  fi; \
 	done;
 
diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in
index 2af8bba44ca9..a24fa059a7a2 100644
--- a/gcc/lto/Make-lang.in
+++ b/gcc/lto/Make-lang.in
@@ -115,7 +115,7 @@ create_fdas_for_lto1: ../stage1-gcc/lto1$(exeext) ../prev-gcc/$(PERF_DATA)
 	  echo $$perf_path; \
 	  if [ -f $$perf_path ]; then \
 	    profile_name=lto1_$$component_in_prev.fda; \
-	    $(CREATE_GCOV) -binary ../stage1-gcc/lto1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 2 || exit 1; \
+	    $(CREATE_GCOV) -binary ../stage1-gcc/lto1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 3 || exit 1; \
 	  fi; \
 	done;
 
@@ -125,7 +125,7 @@ create_fdas_for_lto1: ../stage1-gcc/lto1$(exeext) ../prev-gcc/$(PERF_DATA)
 	  echo $$perf_path; \
 	  if [ -f $$perf_path ]; then \
 	    profile_name=lto1_$$component_in_prev_target.fda; \
-	    $(CREATE_GCOV) -binary ../prev-gcc/lto1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 2 || exit 1; \
+	    $(CREATE_GCOV) -binary ../prev-gcc/lto1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 3 || exit 1; \
 	  fi; \
 	done;
 
diff --git a/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-basic-0.c b/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-basic-0.c
new file mode 100644
index 000000000000..551e5a8a425d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-basic-0.c
@@ -0,0 +1,47 @@
+/* { dg-require-effective-target lto } */
+/* { dg-additional-sources "afdo-lto_priv-basic-1.c" } */
+/* { dg-options "-O2 -flto -fdump-ipa-afdo" } */
+/* { dg-require-profiling "-fauto-profile" } */ 
+
+#define TRIP 1000000000
+
+/* Check against exported symbols.  */
+__attribute__ ((noinline, noipa)) void effect_1 () {}
+__attribute__ ((noinline, noipa)) void effect_2 () {}
+__attribute__ ((noinline, noipa)) static int foo () { return 5; }
+
+/* Prevent GCC from optimizing the loop.  */
+__attribute__ ((noinline, noipa)) int
+use (int x)
+{
+  volatile int y = x;
+  return x;
+}
+
+extern void global ();
+
+int
+main ()
+{
+  for (int i = 0; i < TRIP; i++)
+    {
+      /* Call only 50% of the time.  */
+      if (use (i) < TRIP / 2)
+	global ();
+
+      if (foo () < 5)
+	/* This function is never called.  */
+	effect_1 ();
+      else
+	effect_2 ();
+    }
+}
+
+/* Check that the annotation actually occurs.  */
+/* { dg-final-use-autofdo { scan-ipa-dump-not "No afdo profile for main" afdo } } */
+/* { dg-final-use-autofdo { scan-ipa-dump-not "No afdo profile for use" afdo } } */
+/* { dg-final-use-autofdo { scan-ipa-dump-not "No afdo profile for foo" afdo } } */
+/* { dg-final-use-autofdo { scan-ipa-dump-not "No afdo profile for effect_2" afdo } } */
+
+/* There should be no collision with effect_1 from afdo-lto_priv-basic-1.c.  */
+/* { dg-final-use-autofdo { scan-ipa-dump "No afdo profile for effect_1" afdo } } */
diff --git a/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-basic-1.c b/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-basic-1.c
new file mode 100644
index 000000000000..38601d1a38e4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-basic-1.c
@@ -0,0 +1,20 @@
+/* { dg-require-effective-target lto } */
+/* { dg-additional-sources "afdo-lto_priv-basic-0.c" } */
+/* { dg-options "-O2 -flto -fdump-ipa-afdo" } */
+/* { dg-require-profiling "-fauto-profile" } */ 
+
+__attribute__((noinline, noipa)) static void do_nothing() {}
+__attribute__((noinline, noipa)) static void effect_1() { do_nothing(); }
+__attribute__((noinline, noipa)) static void effect_2() { do_nothing(); }
+
+void global()
+{
+  effect_1();
+  effect_2();
+}
+
+/* Check that the annotation actually occurs.  */
+/* { dg-final-use-autofdo { scan-ipa-dump-not "No afdo profile for global" afdo } } */
+/* { dg-final-use-autofdo { scan-ipa-dump-not "No afdo profile for effect_2" afdo } } */
+/* { dg-final-use-autofdo { scan-ipa-dump-not "No afdo profile for effect_1" afdo } } */
+/* { dg-final-use-autofdo { scan-ipa-dump-not "No afdo profile for do_nothing" afdo } } */
diff --git a/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-header-0.c b/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-header-0.c
new file mode 100644
index 000000000000..b30412284c63
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-header-0.c
@@ -0,0 +1,47 @@
+/* { dg-require-effective-target lto } */
+/* { dg-additional-sources "afdo-lto_priv-header-1.c" } */
+/* { dg-options "-O2 -flto -fdump-ipa-afdo" } */
+/* { dg-require-profiling "-fauto-profile" } */ 
+
+/* Verify that symbols included from headers get their file names set and
+   compared correctly.  */
+
+#define TRIP 1000000000
+
+#include "afdo-lto_priv-header-0.h"
+
+/* Prevent GCC from optimizing the loop.  */
+__attribute__ ((noinline, noipa)) int
+use (int x)
+{
+  volatile int y = x;
+  return x;
+}
+
+extern void global ();
+
+int
+main ()
+{
+  for (int i = 0; i < TRIP; i++)
+    {
+      /* Call only 50% of the time.  */
+      if (use (i) < TRIP / 2)
+	global ();
+
+      if (foo () < 5)
+	/* This function is never called.  */
+	effect_1 ();
+      else
+	effect_2 ();
+    }
+}
+
+/* Check that the annotation actually occurs.  */
+/* { dg-final-use-autofdo { scan-ipa-dump-not "No afdo profile for main" afdo } } */
+/* { dg-final-use-autofdo { scan-ipa-dump-not "No afdo profile for use" afdo } } */
+/* { dg-final-use-autofdo { scan-ipa-dump-not "No afdo profile for foo" afdo } } */
+/* { dg-final-use-autofdo { scan-ipa-dump-not "No afdo profile for effect_2" afdo } } */
+
+/* There should be no collision with effect_1 from afdo-lto_priv-header-1.c.  */
+/* { dg-final-use-autofdo { scan-ipa-dump "No afdo profile for effect_1" afdo } } */
diff --git a/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-header-0.h b/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-header-0.h
new file mode 100644
index 000000000000..ee2a14d8ecad
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-header-0.h
@@ -0,0 +1,3 @@
+__attribute__ ((noinline, noipa)) static void effect_1 () {}
+__attribute__ ((noinline, noipa)) static void effect_2 () {}
+__attribute__ ((noinline, noipa)) static int foo () { return 5; }
diff --git a/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-header-1.c b/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-header-1.c
new file mode 100644
index 000000000000..b9dfe92676e2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-header-1.c
@@ -0,0 +1,18 @@
+/* { dg-require-effective-target lto } */
+/* { dg-additional-sources "afdo-lto_priv-header-0.c" } */
+/* { dg-options "-O2 -flto -fdump-ipa-afdo" } */
+/* { dg-require-profiling "-fauto-profile" } */ 
+
+#include "afdo-lto_priv-header-1.h"
+
+void global()
+{
+  effect_1();
+  effect_2();
+}
+
+/* Check that the annotation actually occurs.  */
+/* { dg-final-use-autofdo { scan-ipa-dump-not "No afdo profile for global" afdo } } */
+/* { dg-final-use-autofdo { scan-ipa-dump-not "No afdo profile for effect_2" afdo } } */
+/* { dg-final-use-autofdo { scan-ipa-dump-not "No afdo profile for effect_1" afdo } } */
+/* { dg-final-use-autofdo { scan-ipa-dump-not "No afdo profile for do_nothing" afdo } } */
diff --git a/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-header-1.h b/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-header-1.h
new file mode 100644
index 000000000000..249c97081d31
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/afdo-lto_priv-header-1.h
@@ -0,0 +1,3 @@
+__attribute__((noinline, noipa)) static void do_nothing() {}
+__attribute__((noinline, noipa)) static void effect_1() { do_nothing(); }
+__attribute__((noinline, noipa)) static void effect_2() { do_nothing(); }
diff --git a/gcc/testsuite/lib/profopt.exp b/gcc/testsuite/lib/profopt.exp
index 81d86c632d17..0001f6798dd3 100644
--- a/gcc/testsuite/lib/profopt.exp
+++ b/gcc/testsuite/lib/profopt.exp
@@ -452,7 +452,7 @@ proc profopt-execute { src } {
 	    # convert profile
 	    if { $run_autofdo == 1 } {
                 set bprefix "afdo."
-		set cmd "create_gcov --binary $execname1 --profile=$tmpdir/$base.perf.data -gcov_version=2 --gcov=$tmpdir/$bprefix$base.$ext"
+		set cmd "create_gcov --binary $execname1 --profile=$tmpdir/$base.perf.data --gcov_version=3 --gcov=$tmpdir/$bprefix$base.$ext"
 		verbose "Running $cmd"
 		set id [remote_spawn "" $cmd]
 		if { $id < 0 } {


More information about the Gcc-cvs mailing list