diff mbox

[2/3] Run profile feedback tests with autofdo

Message ID 20160623143719.17603-3-andi@firstfloor.org
State New
Headers show

Commit Message

Andi Kleen June 23, 2016, 2:37 p.m. UTC
From: ak <ak@138bc75d-0d04-0410-961f-82ee72b054a4>

Extend the existing bprob and tree-prof tests to also run with autofdo.
The test runtimes are really a bit too short for autofdo, but it's
a reasonable sanity check.

This only works natively for now.

dejagnu doesn't seem to support a wrapper for unix tests, so I had
to open code running these tests.  That should be ok due to the
native run restrictions.

gcc/testsuite/:

2016-06-23  Andi Kleen  <ak@linux.intel.com>

	* g++.dg/bprob/bprob.exp: Support autofdo.
	* g++.dg/tree-prof/tree-prof.exp: dito.
	* gcc.dg/tree-prof/tree-prof.exp: dito.
	* gcc.misc-tests/bprob.exp: dito.
	* gfortran.dg/prof/prof.exp: dito.
	* lib/profopt.exp: dito.
	* lib/target-supports.exp: Check for autofdo.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@237732 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/testsuite/ChangeLog                      | 10 ++++
 gcc/testsuite/g++.dg/bprob/bprob.exp         |  8 +++
 gcc/testsuite/g++.dg/tree-prof/tree-prof.exp |  8 +++
 gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp |  8 +++
 gcc/testsuite/gcc.misc-tests/bprob.exp       |  7 +++
 gcc/testsuite/gfortran.dg/prof/prof.exp      |  7 +++
 gcc/testsuite/lib/profopt.exp                | 82 +++++++++++++++++++++++++++-
 gcc/testsuite/lib/target-supports.exp        | 37 +++++++++++++
 8 files changed, 164 insertions(+), 3 deletions(-)

Comments

Bin.Cheng July 12, 2016, 3:13 p.m. UTC | #1
On Thu, Jun 23, 2016 at 3:37 PM, Andi Kleen <andi@firstfloor.org> wrote:
> From: ak <ak@138bc75d-0d04-0410-961f-82ee72b054a4>
>
> Extend the existing bprob and tree-prof tests to also run with autofdo.
> The test runtimes are really a bit too short for autofdo, but it's
> a reasonable sanity check.
>
> This only works natively for now.
>
> dejagnu doesn't seem to support a wrapper for unix tests, so I had
> to open code running these tests.  That should be ok due to the
> native run restrictions.
>
> gcc/testsuite/:
>
> 2016-06-23  Andi Kleen  <ak@linux.intel.com>
>
>         * g++.dg/bprob/bprob.exp: Support autofdo.
>         * g++.dg/tree-prof/tree-prof.exp: dito.
>         * gcc.dg/tree-prof/tree-prof.exp: dito.
>         * gcc.misc-tests/bprob.exp: dito.
>         * gfortran.dg/prof/prof.exp: dito.
>         * lib/profopt.exp: dito.
>         * lib/target-supports.exp: Check for autofdo.
>
> git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@237732 138bc75d-0d04-0410-961f-82ee72b054a4
> ---
>  gcc/testsuite/ChangeLog                      | 10 ++++
>  gcc/testsuite/g++.dg/bprob/bprob.exp         |  8 +++
>  gcc/testsuite/g++.dg/tree-prof/tree-prof.exp |  8 +++
>  gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp |  8 +++
>  gcc/testsuite/gcc.misc-tests/bprob.exp       |  7 +++
>  gcc/testsuite/gfortran.dg/prof/prof.exp      |  7 +++
>  gcc/testsuite/lib/profopt.exp                | 82 +++++++++++++++++++++++++++-
>  gcc/testsuite/lib/target-supports.exp        | 37 +++++++++++++
>  8 files changed, 164 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
> index 287baf6..55f8dbf 100644
> --- a/gcc/testsuite/ChangeLog
> +++ b/gcc/testsuite/ChangeLog
> @@ -1,3 +1,13 @@
> +2016-06-23  Andi Kleen  <ak@linux.intel.com>
> +
> +       * g++.dg/bprob/bprob.exp: Support autofdo.
> +       * g++.dg/tree-prof/tree-prof.exp: dito.
> +       * gcc.dg/tree-prof/tree-prof.exp: dito.
> +       * gcc.misc-tests/bprob.exp: dito.
> +       * gfortran.dg/prof/prof.exp: dito.
> +       * lib/profopt.exp: dito.
> +       * lib/target-supports.exp: Check for autofdo.
> +
>  2016-06-23  Martin Liska  <mliska@suse.cz>
>
>         * gcc.dg/pr71619.c: New test.
> diff --git a/gcc/testsuite/g++.dg/bprob/bprob.exp b/gcc/testsuite/g++.dg/bprob/bprob.exp
> index d555507..4818298 100644
> --- a/gcc/testsuite/g++.dg/bprob/bprob.exp
> +++ b/gcc/testsuite/g++.dg/bprob/bprob.exp
> @@ -53,6 +53,7 @@ if $tracelevel then {
>
>  set profile_options "-fprofile-arcs"
>  set feedback_options "-fbranch-probabilities"
> +set profile_wrapper ""
>
>  # Main loop.
>  foreach profile_option $profile_options feedback_option $feedback_options {
> @@ -65,4 +66,11 @@ foreach profile_option $profile_options feedback_option $feedback_options {
>      }
>  }
>
> +foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.C]] {
> +    if ![runtest_file_p $runtests $src] then {
> +        continue
> +    }
> +    auto-profopt-execute $src
> +}
> +
>  set PROFOPT_OPTIONS $bprob_save_profopt_options
> diff --git a/gcc/testsuite/g++.dg/tree-prof/tree-prof.exp b/gcc/testsuite/g++.dg/tree-prof/tree-prof.exp
> index 7a4b5cb..26ee0b3 100644
> --- a/gcc/testsuite/g++.dg/tree-prof/tree-prof.exp
> +++ b/gcc/testsuite/g++.dg/tree-prof/tree-prof.exp
> @@ -44,6 +44,7 @@ set PROFOPT_OPTIONS [list {}]
>  # profile data.
>  set profile_option "-fprofile-generate -D_PROFILE_GENERATE"
>  set feedback_option "-fprofile-use -D_PROFILE_USE"
> +set profile_wrapper ""
>
>  foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.C]] {
>      # If we're only testing specific files and this isn't one of them, skip it.
> @@ -53,4 +54,11 @@ foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.C]] {
>      profopt-execute $src
>  }
>
> +foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.C]] {
> +    if ![runtest_file_p $runtests $src] then {
> +        continue
> +    }
> +    auto-profopt-execute $src
> +}
> +
>  set PROFOPT_OPTIONS $treeprof_save_profopt_options
> diff --git a/gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp b/gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp
> index 650ad8d..aaccf19 100644
> --- a/gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp
> +++ b/gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp
> @@ -44,6 +44,7 @@ set PROFOPT_OPTIONS [list {}]
>  # profile data.
>  set profile_option "-fprofile-generate -D_PROFILE_GENERATE"
>  set feedback_option "-fprofile-use -D_PROFILE_USE"
> +set profile_wrapper ""
>
>  foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
>      # If we're only testing specific files and this isn't one of them, skip it.
> @@ -53,4 +54,11 @@ foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
>      profopt-execute $src
>  }
>
> +foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
> +    if ![runtest_file_p $runtests $src] then {
> +        continue
> +    }
> +    auto-profopt-execute $src
> +}
> +
>  set PROFOPT_OPTIONS $treeprof_save_profopt_options
> diff --git a/gcc/testsuite/gcc.misc-tests/bprob.exp b/gcc/testsuite/gcc.misc-tests/bprob.exp
> index 52dcb1f..132bfe3 100644
> --- a/gcc/testsuite/gcc.misc-tests/bprob.exp
> +++ b/gcc/testsuite/gcc.misc-tests/bprob.exp
> @@ -41,6 +41,7 @@ load_lib profopt.exp
>  set bprob_save_profopt_options $PROFOPT_OPTIONS
>  set PROFOPT_OPTIONS [list { -O2 } { -O3  }]
>
> +set profile_wrapper ""
>  set profile_options "-fprofile-arcs"
>  set feedback_options "-fbranch-probabilities"
>
> @@ -54,4 +55,10 @@ foreach profile_option $profile_options feedback_option $feedback_options {
>      }
>  }
>
> +foreach src [lsort [glob -nocomplain $srcdir/$subdir/bprob-*.c]] {
> +    if ![runtest_file_p $runtests $src] then {
> +        continue
> +    }
> +    auto-profopt-execute $src
> +}
>  set PROFOPT_OPTIONS $bprob_save_profopt_options
> diff --git a/gcc/testsuite/gfortran.dg/prof/prof.exp b/gcc/testsuite/gfortran.dg/prof/prof.exp
> index 0bad01d..acc8ed0 100644
> --- a/gcc/testsuite/gfortran.dg/prof/prof.exp
> +++ b/gcc/testsuite/gfortran.dg/prof/prof.exp
> @@ -53,4 +53,11 @@ foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.f*]] {
>      profopt-execute $src
>  }
>
> +foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.f*]] {
> +    if ![runtest_file_p $runtests $src] then {
> +        continue
> +    }
> +    auto-profopt-execute $src
> +}
> +
>  set PROFOPT_OPTIONS $treeprof_save_profopt_options
> diff --git a/gcc/testsuite/lib/profopt.exp b/gcc/testsuite/lib/profopt.exp
> index 0aea6c4..b3e2b2e 100644
> --- a/gcc/testsuite/lib/profopt.exp
> +++ b/gcc/testsuite/lib/profopt.exp
> @@ -36,7 +36,7 @@ load_lib gcc-dg.exp
>  global PROFOPT_OPTIONS perf_delta
>
>  # The including .exp file must define these.
> -global tool profile_option feedback_option prof_ext
> +global tool profile_option feedback_option prof_ext profile_wrapper
>  if ![info exists tool] {
>      error "Tools is not specified."
>  }
> @@ -229,6 +229,31 @@ proc profopt-get-options { src } {
>      return ${dg-extra-tool-flags}
>  }
>
> +# auto-profopt-execute -- Compile for auto profiling and then feedback,
> +# then normal. SRC is the full path name of the testcase.
> +proc auto-profopt-execute { src } {
> +    global profile_wrapper
> +    global profile_option
> +    global feedback_option
> +    global run_autofdo
> +    global srcdir
> +
> +    if { ! [check_profiling_available "-fauto-profile"] } {
> +        regsub "(?q)$srcdir/" $src "" testcase
> +        unsupported "$testcase"
> +        return
> +    }
> +    set profile_wrapper [profopt-perf-wrapper]
> +    set profile_option "-g"
> +    set feedback_option "-fauto-profile"
> +    set run_autofdo 1
> +    profopt-execute $src
> +    unset profile_wrapper
> +    unset profile_option
> +    unset feedback_option
> +    unset run_autofdo
> +}
> +
>  #
>  # c-prof-execute -- compile for profiling and then feedback, then normal
>  #
> @@ -238,6 +263,7 @@ proc profopt-execute { src } {
>      global srcdir tmpdir
>      global PROFOPT_OPTIONS
>      global tool profile_option feedback_option prof_ext perf_ext perf_delta
> +    global profile_wrapper run_autofdo ld_library_path
>      global generate_final_code use_final_code
>      global verbose
>      global testname_with_flags
> @@ -248,6 +274,12 @@ proc profopt-execute { src } {
>      if ![info exists feedback_option] {
>          error "No feedback option specified for second compile."
>      }
> +    if ![info exists profile_wrapper] {
> +       set profile_wrapper ""
> +    }
> +    if ![info exists run_autofdo] {
> +       set run_autofdo ""
> +    }
>
>      # Use the default option list or one defined for a set of tests.
>      if ![info exists PROFOPT_OPTIONS] {
> @@ -313,6 +345,7 @@ proc profopt-execute { src } {
>         # valid, by running it after dg-additional-files-options.
>         foreach ext $prof_ext {
>             profopt-target-cleanup $tmpdir $base $ext
> +           profopt-target-cleanup $tmpdir perf data
>         }
>
>         # Tree profiling requires TLS runtime support, which may need
> @@ -335,12 +368,50 @@ proc profopt-execute { src } {
>         }
>
>         # Run the profiled test.
> +       if { $run_autofdo == 1 } {
> +           if { ![info exists ld_library_path]} {
> +               set ld_library_path ""
> +           }
> +           set orig_ld_library_path "[getenv LD_LIBRARY_PATH]"
> +           setenv LD_LIBRARY_PATH "$ld_library_path:$orig_ld_library_path"
> +           verbose "Running $profile_wrapper $execname1"
> +           set id [remote_spawn "" "$profile_wrapper $execname1" "readonly"]
> +           setenv LD_LIBRARY_PATH $orig_ld_library_path
> +           if { $id < 0 } {
> +               warning "Failed to run profiler"
> +               set status "fail"
> +           } else {
> +               set result [remote_wait "" 300]
> +               set status [lindex $result 0]
> +               verbose "perf result $result"
> +               if { $status == 0 } {
> +                   set status "pass"
> +               } else {
> +                   set status "fail"
> +               }
> +           }
> +       } else {
> +           set result [${tool}_load $execname1 "" ""]
> +           set status [lindex $result 0]
> +       }
>
> -       set result [${tool}_load $execname1 "" ""]
> -       set status [lindex $result 0]
>         set missing_file 0
>         # Make sure the profile data was generated, and fail if not.
>         if { $status == "pass" } {
> +           # convert profile
> +           if { $run_autofdo == 1 } {
> +               set cmd "create_gcov --binary $execname1 --profile=perf.data -gcov_version=1 --gcov=$tmpdir/$base.$ext"
> +               verbose "Running $cmd"
> +               set id [remote_spawn "" $cmd]
> +               if { $id < 0 } {
> +                   unsupported "$testcase: Cannot run $cmd"
> +                   set status "fail"
> +                   return
> +               }
> +               set status [remote_wait "" 300]
> +               set status "pass"
> +           }
> +
>             foreach ext $prof_ext {
>                 remote_upload target $tmpdir/$base.$ext
>                 set files [glob -nocomplain $base.$ext]
> @@ -375,6 +446,10 @@ proc profopt-execute { src } {
>         set options "$extra_options"
>         lappend options "additional_flags=$option $extra_flags $feedback_option"
>         set optstr "$option $feedback_option"
> +       if { [string first "-fauto-profile" $options] >= 0} {
> +           set options [regsub -- "-fauto-profile" $options "-fauto-profile=$tmpdir/$base.$ext"]
> +       }
> +
>         set comp_output [${tool}_target_compile "$src" "$execname2" "executable" $options]
>
>         # Prune warnings we know are unwanted.
> @@ -399,6 +474,7 @@ proc profopt-execute { src } {
>         # Remove the profiling data files.
>         foreach ext $prof_ext {
>             profopt-target-cleanup $tmpdir $base $ext
> +           profopt-target-cleanup $tmpdir perf data
>         }
>
>         if { $status != "pass" } {
> diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
> index 1b1d03a..62267cf 100644
> --- a/gcc/testsuite/lib/target-supports.exp
> +++ b/gcc/testsuite/lib/target-supports.exp
> @@ -508,6 +508,13 @@ proc check_effective_target_keeps_null_pointer_checks { } {
>      return 0
>  }
>
> +# Return the autofdo profile wrapper
> +
> +proc profopt-perf-wrapper { } {
> +    global srcdir
> +    return "$srcdir/../config/i386/gcc-auto-profile -o perf.data "
> +}
> +
>  # Return true if profiling is supported on the target.
>
>  proc check_profiling_available { test_what } {
> @@ -525,6 +532,36 @@ proc check_profiling_available { test_what } {
>         }
>      }
>
> +    if { $test_what == "-fauto-profile" } {
> +       if { ! ([istarget x86_64-*-linux*] || [istarget i?86-*-linux*]) } {
> +            verbose "autofdo only supported on linux"
> +            return 0
> +        }
> +       # not cross compiling?
> +       if { ![isnative] } {
> +           verbose "autofdo not supported for non native builds"
> +           return 0
> +       }
> +       set event [profopt-perf-wrapper]
> +       if {$event == "" } {
> +           verbose "autofdo not supported"
> +           return 0
> +       }
> +        global srcdir
> +       set status [remote_exec host "$srcdir/../config/i386/gcc-auto-profile" "true -v >/dev/null"]
> +       if { [lindex $status 0] != 0 } {
> +           verbose "autofdo not supported because perf does not work"
> +           return 0
> +       }
> +
> +       # no good way to check this in advance -- check later instead.
> +       #set status [remote_exec host "create_gcov" "2>/dev/null"]
> +       #if { [lindex $status 0] != 255 } {
> +        #    verbose "autofdo not supported due to missing create_gcov"
> +        #    return 0
> +        #}
> +    }
> +
>      # Support for -p on solaris2 relies on mcrt1.o which comes with the
>      # vendor compiler.  We cannot reliably predict the directory where the
>      # vendor compiler (and thus mcrt1.o) is installed so we can't
> --
> 2.8.3
>
Hi,
After this patch, I got below test results with command line: make
check-gcc RUNTESTFLAGS="tree-prof.exp" -k

PASS: gcc.dg/tree-prof/20041218-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/20041218-1.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/20041218-1.gcda
PASS: gcc.dg/tree-prof/20050826-2.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/20050826-2.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/20050826-2.gcda
PASS: gcc.dg/tree-prof/bb-reorg.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/bb-reorg.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/bb-reorg.gcda
PASS: gcc.dg/tree-prof/cmpsf-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/cmpsf-1.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/cmpsf-1.gcda
PASS: gcc.dg/tree-prof/cold_partition_label.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/cold_partition_label.c: Cannot run
create_gcov --binary
/data/work/trunk/build/gcc/testsuite/gcc/cold_partition_label.gcda
PASS: gcc.dg/tree-prof/comp-goto-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/comp-goto-1.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/comp-goto-1.gcda
PASS: gcc.dg/tree-prof/crossmodule-indircall-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/crossmodule-indircall-1.c: Cannot run
create_gcov --binary
/data/work/trunk/build/gcc/testsuite/gcc/crossmodule-indircall-1.gcda
PASS: gcc.dg/tree-prof/crossmodule-indircall-1a.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/crossmodule-indircall-1a.c: Cannot run
create_gcov --binary
/data/work/trunk/build/gcc/testsuite/gcc/crossmodule-indircall-1a.gcda
PASS: gcc.dg/tree-prof/ic-misattribution-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/ic-misattribution-1.c: Cannot run
create_gcov --binary
/data/work/trunk/build/gcc/testsuite/gcc/ic-misattribution-1.gcda
PASS: gcc.dg/tree-prof/ic-misattribution-1a.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/ic-misattribution-1a.c: Cannot run
create_gcov --binary
/data/work/trunk/build/gcc/testsuite/gcc/ic-misattribution-1a.gcda
PASS: gcc.dg/tree-prof/indir-call-prof.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/indir-call-prof.c: Cannot run
create_gcov --binary
/data/work/trunk/build/gcc/testsuite/gcc/indir-call-prof.gcda
PASS: gcc.dg/tree-prof/inliner-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/inliner-1.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/inliner-1.gcda
PASS: gcc.dg/tree-prof/merge_block.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/merge_block.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/merge_block.gcda
PASS: gcc.dg/tree-prof/peel-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/peel-1.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/peel-1.gcda
PASS: gcc.dg/tree-prof/pr34999.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/pr34999.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/pr34999.gcda
PASS: gcc.dg/tree-prof/pr44777.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/pr44777.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/pr44777.gcda
PASS: gcc.dg/tree-prof/pr45354.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/pr45354.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/pr45354.gcda
PASS: gcc.dg/tree-prof/pr47187.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/pr47187.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/pr47187.gcda
PASS: gcc.dg/tree-prof/pr49299-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/pr49299-1.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/pr49299-1.gcda
PASS: gcc.dg/tree-prof/pr49299-2.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/pr49299-2.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/pr49299-2.gcda
PASS: gcc.dg/tree-prof/pr50907.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/pr50907.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/pr50907.gcda
PASS: gcc.dg/tree-prof/pr52027.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/pr52027.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/pr52027.gcda
PASS: gcc.dg/tree-prof/pr52150.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/pr52150.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/pr52150.gcda
PASS: gcc.dg/tree-prof/pr59003.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/pr59003.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/pr59003.gcda
PASS: gcc.dg/tree-prof/prof-robust-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/prof-robust-1.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/prof-robust-1.gcda
PASS: gcc.dg/tree-prof/stringop-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/stringop-1.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/stringop-1.gcda
PASS: gcc.dg/tree-prof/stringop-2.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/stringop-2.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/stringop-2.gcda
PASS: gcc.dg/tree-prof/switch-case-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/switch-case-1.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/switch-case-1.gcda
PASS: gcc.dg/tree-prof/switch-case-2.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/switch-case-2.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/switch-case-2.gcda
PASS: gcc.dg/tree-prof/time-profiler-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/time-profiler-1.c: Cannot run
create_gcov --binary
/data/work/trunk/build/gcc/testsuite/gcc/time-profiler-1.gcda
PASS: gcc.dg/tree-prof/time-profiler-2.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/time-profiler-2.c: Cannot run
create_gcov --binary
/data/work/trunk/build/gcc/testsuite/gcc/time-profiler-2.gcda
PASS: gcc.dg/tree-prof/tracer-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/tracer-1.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/tracer-1.gcda
PASS: gcc.dg/tree-prof/unroll-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/unroll-1.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/unroll-1.gcda
PASS: gcc.dg/tree-prof/update-cunroll-2.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/update-cunroll-2.c: Cannot run
create_gcov --binary
/data/work/trunk/build/gcc/testsuite/gcc/update-cunroll-2.gcda
PASS: gcc.dg/tree-prof/update-loopch.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/update-loopch.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/update-loopch.gcda
PASS: gcc.dg/tree-prof/update-tailcall.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/update-tailcall.c: Cannot run
create_gcov --binary
/data/work/trunk/build/gcc/testsuite/gcc/update-tailcall.gcda
PASS: gcc.dg/tree-prof/va-arg-pack-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/va-arg-pack-1.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/va-arg-pack-1.gcda
PASS: gcc.dg/tree-prof/val-prof-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/val-prof-1.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/val-prof-1.gcda
PASS: gcc.dg/tree-prof/val-prof-2.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/val-prof-2.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/val-prof-2.gcda
PASS: gcc.dg/tree-prof/val-prof-3.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/val-prof-3.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/val-prof-3.gcda
PASS: gcc.dg/tree-prof/val-prof-4.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/val-prof-4.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/val-prof-4.gcda
PASS: gcc.dg/tree-prof/val-prof-5.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/val-prof-5.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/val-prof-5.gcda
PASS: gcc.dg/tree-prof/val-prof-6.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/val-prof-6.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/val-prof-6.gcda
PASS: gcc.dg/tree-prof/val-prof-7.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/val-prof-7.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/val-prof-7.gcda
PASS: gcc.dg/tree-prof/wcoverage-mismatch.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/wcoverage-mismatch.c: Cannot run
create_gcov --binary
/data/work/trunk/build/gcc/testsuite/gcc/wcoverage-mismatch.gcda

Before this patch, gcc test doesn't build/test these with "-g" option.

Also I got unstable test result in tree-prof.exp if I run
aforementioned command line with -jnum (parallelly).  Does the patch
has problem in parallel testing?

Thanks,
bin
Andi Kleen July 14, 2016, 10:55 a.m. UTC | #2
> After this patch, I got below test results with command line: make
> check-gcc RUNTESTFLAGS="tree-prof.exp" -k

That is expected if you don't have autofdo. You would prefer to hide it?

> Also I got unstable test result in tree-prof.exp if I run
> aforementioned command line with -jnum (parallelly).  Does the patch
> has problem in parallel testing?

I haven't seen that. Unstable in what way?

-Andi
Bin.Cheng July 14, 2016, 11:06 a.m. UTC | #3
On Thu, Jul 14, 2016 at 11:55 AM, Andi Kleen <andi@firstfloor.org> wrote:
>> After this patch, I got below test results with command line: make
>> check-gcc RUNTESTFLAGS="tree-prof.exp" -k
>
> That is expected if you don't have autofdo. You would prefer to hide it?
>
>> Also I got unstable test result in tree-prof.exp if I run
>> aforementioned command line with -jnum (parallelly).  Does the patch
>> has problem in parallel testing?
>
> I haven't seen that. Unstable in what way?
For GCC doesn't support FDO, it run below tests as you said:

PASS: gcc.dg/tree-prof/20041218-1.c compilation,  -g
UNSUPPORTED: gcc.dg/tree-prof/20041218-1.c: Cannot run create_gcov
--binary /data/work/trunk/build/gcc/testsuite/gcc/20041218-1.gcda

Normally, it doesn't create gcov data file, thus the next test is
unsupported.  I guess in parallel test, the second test picks up gcov
data files from other process, which results in random pass.
Is it possible to not have these when fdo is supported?

Thanks,
bin

>
> -Andi
Bin.Cheng July 14, 2016, 11:07 a.m. UTC | #4
On Thu, Jul 14, 2016 at 12:06 PM, Bin.Cheng <amker.cheng@gmail.com> wrote:
> On Thu, Jul 14, 2016 at 11:55 AM, Andi Kleen <andi@firstfloor.org> wrote:
>>> After this patch, I got below test results with command line: make
>>> check-gcc RUNTESTFLAGS="tree-prof.exp" -k
>>
>> That is expected if you don't have autofdo. You would prefer to hide it?
>>
>>> Also I got unstable test result in tree-prof.exp if I run
>>> aforementioned command line with -jnum (parallelly).  Does the patch
>>> has problem in parallel testing?
>>
>> I haven't seen that. Unstable in what way?
> For GCC doesn't support FDO, it run below tests as you said:
>
> PASS: gcc.dg/tree-prof/20041218-1.c compilation,  -g
> UNSUPPORTED: gcc.dg/tree-prof/20041218-1.c: Cannot run create_gcov
> --binary /data/work/trunk/build/gcc/testsuite/gcc/20041218-1.gcda
>
> Normally, it doesn't create gcov data file, thus the next test is
> unsupported.  I guess in parallel test, the second test picks up gcov
> data files from other process, which results in random pass.
> Is it possible to not have these when fdo is supported?
Hmm, typo:  s/supported/not supported/.

Thanks,
bin
Andi Kleen July 14, 2016, 10:33 p.m. UTC | #5
> >> I haven't seen that. Unstable in what way?
> > For GCC doesn't support FDO, it run below tests as you said:
> >
> > PASS: gcc.dg/tree-prof/20041218-1.c compilation,  -g
> > UNSUPPORTED: gcc.dg/tree-prof/20041218-1.c: Cannot run create_gcov
> > --binary /data/work/trunk/build/gcc/testsuite/gcc/20041218-1.gcda
> >
> > Normally, it doesn't create gcov data file, thus the next test is
> > unsupported.  I guess in parallel test, the second test picks up gcov
> > data files from other process, which results in random pass.
> > Is it possible to not have these when fdo is supported?
> Hmm, typo:  s/supported/not supported/.

I don't see how this can happen: as you can see the .gcda file name
is unique for each test case.

I think there may be problems with the perf.data, could add a postfix.
But you should only see that with real autofdo.

-Andi
Bin.Cheng July 15, 2016, 8:37 a.m. UTC | #6
On Thu, Jul 14, 2016 at 11:33 PM, Andi Kleen <andi@firstfloor.org> wrote:
>> >> I haven't seen that. Unstable in what way?
>> > For GCC doesn't support FDO, it run below tests as you said:
>> >
>> > PASS: gcc.dg/tree-prof/20041218-1.c compilation,  -g
>> > UNSUPPORTED: gcc.dg/tree-prof/20041218-1.c: Cannot run create_gcov
>> > --binary /data/work/trunk/build/gcc/testsuite/gcc/20041218-1.gcda
>> >
>> > Normally, it doesn't create gcov data file, thus the next test is
>> > unsupported.  I guess in parallel test, the second test picks up gcov
>> > data files from other process, which results in random pass.
>> > Is it possible to not have these when fdo is supported?
>> Hmm, typo:  s/supported/not supported/.
>
> I don't see how this can happen: as you can see the .gcda file name
> is unique for each test case.
>
> I think there may be problems with the perf.data, could add a postfix.
> But you should only see that with real autofdo.
Don't know.  I only configured/built GCC on x86_64 with below command lines:

$ ../gcc/configure --prefix=...
--enable-languages=c,c++,fortran,go,java,lto,objc,obj-c++
--with-build-config=bootstrap-O3 --disable-werror
$ make && make install

Not sure what the status for autofdo is in this case.  "make check -k"
is stable for me, but "make check -k -j#" gives unstable result in
tree-prof.exp tests.  Anything I did wrong?

Thanks,
bin
Jeff Law July 15, 2016, 7:43 p.m. UTC | #7
On 07/15/2016 02:37 AM, Bin.Cheng wrote:
> On Thu, Jul 14, 2016 at 11:33 PM, Andi Kleen <andi@firstfloor.org> wrote:
>>>>> I haven't seen that. Unstable in what way?
>>>> For GCC doesn't support FDO, it run below tests as you said:
>>>>
>>>> PASS: gcc.dg/tree-prof/20041218-1.c compilation,  -g
>>>> UNSUPPORTED: gcc.dg/tree-prof/20041218-1.c: Cannot run create_gcov
>>>> --binary /data/work/trunk/build/gcc/testsuite/gcc/20041218-1.gcda
>>>>
>>>> Normally, it doesn't create gcov data file, thus the next test is
>>>> unsupported.  I guess in parallel test, the second test picks up gcov
>>>> data files from other process, which results in random pass.
>>>> Is it possible to not have these when fdo is supported?
>>> Hmm, typo:  s/supported/not supported/.
>>
>> I don't see how this can happen: as you can see the .gcda file name
>> is unique for each test case.
>>
>> I think there may be problems with the perf.data, could add a postfix.
>> But you should only see that with real autofdo.
> Don't know.  I only configured/built GCC on x86_64 with below command lines:
>
> $ ../gcc/configure --prefix=...
> --enable-languages=c,c++,fortran,go,java,lto,objc,obj-c++
> --with-build-config=bootstrap-O3 --disable-werror
> $ make && make install
>
> Not sure what the status for autofdo is in this case.  "make check -k"
> is stable for me, but "make check -k -j#" gives unstable result in
> tree-prof.exp tests.  Anything I did wrong?
I'm seeing unstable results as well, but haven't dug into it at all. 
It's definitely autofdo testing though -- If I remove the 
gcc-auto-profile script I get consistent results from one run to the next.

jeff
Andi Kleen July 15, 2016, 8:53 p.m. UTC | #8
> >Not sure what the status for autofdo is in this case.  "make check -k"
> >is stable for me, but "make check -k -j#" gives unstable result in
> >tree-prof.exp tests.  Anything I did wrong?
> I'm seeing unstable results as well, but haven't dug into it at all.
> It's definitely autofdo testing though -- If I remove the
> gcc-auto-profile script I get consistent results from one run to the
> next.

Ok. I'll investigate.
-Andi
Martin Liška July 25, 2016, 11:08 a.m. UTC | #9
On 07/15/2016 10:37 AM, Bin.Cheng wrote:
> On Thu, Jul 14, 2016 at 11:33 PM, Andi Kleen <andi@firstfloor.org> wrote:
>>>>> I haven't seen that. Unstable in what way?
>>>> For GCC doesn't support FDO, it run below tests as you said:
>>>>
>>>> PASS: gcc.dg/tree-prof/20041218-1.c compilation,  -g
>>>> UNSUPPORTED: gcc.dg/tree-prof/20041218-1.c: Cannot run create_gcov
>>>> --binary /data/work/trunk/build/gcc/testsuite/gcc/20041218-1.gcda
>>>>
>>>> Normally, it doesn't create gcov data file, thus the next test is
>>>> unsupported.  I guess in parallel test, the second test picks up gcov
>>>> data files from other process, which results in random pass.
>>>> Is it possible to not have these when fdo is supported?
>>> Hmm, typo:  s/supported/not supported/.
>>
>> I don't see how this can happen: as you can see the .gcda file name
>> is unique for each test case.
>>
>> I think there may be problems with the perf.data, could add a postfix.
>> But you should only see that with real autofdo.
> Don't know.  I only configured/built GCC on x86_64 with below command lines:
> 
> $ ../gcc/configure --prefix=...
> --enable-languages=c,c++,fortran,go,java,lto,objc,obj-c++
> --with-build-config=bootstrap-O3 --disable-werror
> $ make && make install
> 
> Not sure what the status for autofdo is in this case.  "make check -k"
> is stable for me, but "make check -k -j#" gives unstable result in
> tree-prof.exp tests.  Anything I did wrong?
> 
> Thanks,
> bin
> 

I can confirm that I see the same problem on a Xeon machine (../configure && make && make check -k -jX).
I see many:

 g++.dg/tree-prof/pr35545.C: Cannot run create_gcov --binary /home/marxin/Programming/gcc/objdir/gcc/testsuite/g++/pr35545.x01 --profile=perf.data -gcov_version=1 --gcov=/home/marxin/Programming/gcc/objdir/gcc/testsuite/g++/pr35545.gcda

Thanks,
Martin
Andi Kleen July 26, 2016, 4:21 a.m. UTC | #10
On Mon, Jul 25, 2016 at 01:08:43PM +0200, Martin Liška wrote:
> On 07/15/2016 10:37 AM, Bin.Cheng wrote:
> > On Thu, Jul 14, 2016 at 11:33 PM, Andi Kleen <andi@firstfloor.org> wrote:
> >>>>> I haven't seen that. Unstable in what way?
> >>>> For GCC doesn't support FDO, it run below tests as you said:
> >>>>
> >>>> PASS: gcc.dg/tree-prof/20041218-1.c compilation,  -g
> >>>> UNSUPPORTED: gcc.dg/tree-prof/20041218-1.c: Cannot run create_gcov
> >>>> --binary /data/work/trunk/build/gcc/testsuite/gcc/20041218-1.gcda
> >>>>
> >>>> Normally, it doesn't create gcov data file, thus the next test is
> >>>> unsupported.  I guess in parallel test, the second test picks up gcov
> >>>> data files from other process, which results in random pass.
> >>>> Is it possible to not have these when fdo is supported?
> >>> Hmm, typo:  s/supported/not supported/.
> >>
> >> I don't see how this can happen: as you can see the .gcda file name
> >> is unique for each test case.
> >>
> >> I think there may be problems with the perf.data, could add a postfix.
> >> But you should only see that with real autofdo.
> > Don't know.  I only configured/built GCC on x86_64 with below command lines:
> > 
> > $ ../gcc/configure --prefix=...
> > --enable-languages=c,c++,fortran,go,java,lto,objc,obj-c++
> > --with-build-config=bootstrap-O3 --disable-werror
> > $ make && make install
> > 
> > Not sure what the status for autofdo is in this case.  "make check -k"
> > is stable for me, but "make check -k -j#" gives unstable result in
> > tree-prof.exp tests.  Anything I did wrong?
> > 
> > Thanks,
> > bin
> > 
> 
> I can confirm that I see the same problem on a Xeon machine (../configure && make && make check -k -jX).
> I see many:
> 
>  g++.dg/tree-prof/pr35545.C: Cannot run create_gcov --binary /home/marxin/Programming/gcc/objdir/gcc/testsuite/g++/pr35545.x01 --profile=perf.data -gcov_version=1 --gcov=/home/marxin/Programming/gcc/objdir/gcc/testsuite/g++/pr35545.gcda

Well that's expected if you don't have autofdo installed or perf with
lbrs is not working. The test case will be UNSUP in this case.

But it's not expected that it is not deterministic, so that it changes
run to run. Do you see that? Or some other problem? Please describe
it exactly.

If yes, did it start before r238320 or only afer?

-Andi
Jeff Law July 26, 2016, 4:25 a.m. UTC | #11
On 07/25/2016 10:21 PM, Andi Kleen wrote:
> On Mon, Jul 25, 2016 at 01:08:43PM +0200, Martin Liška wrote:
>> On 07/15/2016 10:37 AM, Bin.Cheng wrote:
>>> On Thu, Jul 14, 2016 at 11:33 PM, Andi Kleen <andi@firstfloor.org> wrote:
>>>>>>> I haven't seen that. Unstable in what way?
>>>>>> For GCC doesn't support FDO, it run below tests as you said:
>>>>>>
>>>>>> PASS: gcc.dg/tree-prof/20041218-1.c compilation,  -g
>>>>>> UNSUPPORTED: gcc.dg/tree-prof/20041218-1.c: Cannot run create_gcov
>>>>>> --binary /data/work/trunk/build/gcc/testsuite/gcc/20041218-1.gcda
>>>>>>
>>>>>> Normally, it doesn't create gcov data file, thus the next test is
>>>>>> unsupported.  I guess in parallel test, the second test picks up gcov
>>>>>> data files from other process, which results in random pass.
>>>>>> Is it possible to not have these when fdo is supported?
>>>>> Hmm, typo:  s/supported/not supported/.
>>>>
>>>> I don't see how this can happen: as you can see the .gcda file name
>>>> is unique for each test case.
>>>>
>>>> I think there may be problems with the perf.data, could add a postfix.
>>>> But you should only see that with real autofdo.
>>> Don't know.  I only configured/built GCC on x86_64 with below command lines:
>>>
>>> $ ../gcc/configure --prefix=...
>>> --enable-languages=c,c++,fortran,go,java,lto,objc,obj-c++
>>> --with-build-config=bootstrap-O3 --disable-werror
>>> $ make && make install
>>>
>>> Not sure what the status for autofdo is in this case.  "make check -k"
>>> is stable for me, but "make check -k -j#" gives unstable result in
>>> tree-prof.exp tests.  Anything I did wrong?
>>>
>>> Thanks,
>>> bin
>>>
>>
>> I can confirm that I see the same problem on a Xeon machine (../configure && make && make check -k -jX).
>> I see many:
>>
>>  g++.dg/tree-prof/pr35545.C: Cannot run create_gcov --binary /home/marxin/Programming/gcc/objdir/gcc/testsuite/g++/pr35545.x01 --profile=perf.data -gcov_version=1 --gcov=/home/marxin/Programming/gcc/objdir/gcc/testsuite/g++/pr35545.gcda
>
> Well that's expected if you don't have autofdo installed or perf with
> lbrs is not working. The test case will be UNSUP in this case.
>
> But it's not expected that it is not deterministic, so that it changes
> run to run. Do you see that? Or some other problem? Please describe
> it exactly.
It definitely changes run to run for me.


Jeff
Andi Kleen July 26, 2016, 4:28 a.m. UTC | #12
> >But it's not expected that it is not deterministic, so that it changes
> >run to run. Do you see that? Or some other problem? Please describe
> >it exactly.
> It definitely changes run to run for me.

And do you have autofdo installed? (create_gcov)

-Andi
Martin Liška July 27, 2016, 8:29 a.m. UTC | #13
On 07/26/2016 06:28 AM, Andi Kleen wrote:
> And do you have autofdo installed? (create_gcov)
> 
> -Andi

Ah, sorry for the false alarm, create_gcov is really missing on my distribution.

Martin
Jeff Law July 27, 2016, 8:20 p.m. UTC | #14
On 07/25/2016 10:28 PM, Andi Kleen wrote:
>>> But it's not expected that it is not deterministic, so that it changes
>>> run to run. Do you see that? Or some other problem? Please describe
>>> it exactly.
>> It definitely changes run to run for me.
>
> And do you have autofdo installed? (create_gcov)
No.

jeff
diff mbox

Patch

diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 287baf6..55f8dbf 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,13 @@ 
+2016-06-23  Andi Kleen  <ak@linux.intel.com>
+
+	* g++.dg/bprob/bprob.exp: Support autofdo.
+	* g++.dg/tree-prof/tree-prof.exp: dito.
+	* gcc.dg/tree-prof/tree-prof.exp: dito.
+	* gcc.misc-tests/bprob.exp: dito.
+	* gfortran.dg/prof/prof.exp: dito.
+	* lib/profopt.exp: dito.
+	* lib/target-supports.exp: Check for autofdo.
+
 2016-06-23  Martin Liska  <mliska@suse.cz>
 
 	* gcc.dg/pr71619.c: New test.
diff --git a/gcc/testsuite/g++.dg/bprob/bprob.exp b/gcc/testsuite/g++.dg/bprob/bprob.exp
index d555507..4818298 100644
--- a/gcc/testsuite/g++.dg/bprob/bprob.exp
+++ b/gcc/testsuite/g++.dg/bprob/bprob.exp
@@ -53,6 +53,7 @@  if $tracelevel then {
 
 set profile_options "-fprofile-arcs"
 set feedback_options "-fbranch-probabilities"
+set profile_wrapper ""
 
 # Main loop.
 foreach profile_option $profile_options feedback_option $feedback_options {
@@ -65,4 +66,11 @@  foreach profile_option $profile_options feedback_option $feedback_options {
     }
 }
 
+foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.C]] {
+    if ![runtest_file_p $runtests $src] then {
+        continue
+    }
+    auto-profopt-execute $src
+}
+
 set PROFOPT_OPTIONS $bprob_save_profopt_options
diff --git a/gcc/testsuite/g++.dg/tree-prof/tree-prof.exp b/gcc/testsuite/g++.dg/tree-prof/tree-prof.exp
index 7a4b5cb..26ee0b3 100644
--- a/gcc/testsuite/g++.dg/tree-prof/tree-prof.exp
+++ b/gcc/testsuite/g++.dg/tree-prof/tree-prof.exp
@@ -44,6 +44,7 @@  set PROFOPT_OPTIONS [list {}]
 # profile data.
 set profile_option "-fprofile-generate -D_PROFILE_GENERATE"
 set feedback_option "-fprofile-use -D_PROFILE_USE"
+set profile_wrapper ""
 
 foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.C]] {
     # If we're only testing specific files and this isn't one of them, skip it.
@@ -53,4 +54,11 @@  foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.C]] {
     profopt-execute $src
 }
 
+foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.C]] {
+    if ![runtest_file_p $runtests $src] then {
+        continue
+    }
+    auto-profopt-execute $src
+}
+
 set PROFOPT_OPTIONS $treeprof_save_profopt_options
diff --git a/gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp b/gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp
index 650ad8d..aaccf19 100644
--- a/gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp
+++ b/gcc/testsuite/gcc.dg/tree-prof/tree-prof.exp
@@ -44,6 +44,7 @@  set PROFOPT_OPTIONS [list {}]
 # profile data.
 set profile_option "-fprofile-generate -D_PROFILE_GENERATE"
 set feedback_option "-fprofile-use -D_PROFILE_USE"
+set profile_wrapper ""
 
 foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
     # If we're only testing specific files and this isn't one of them, skip it.
@@ -53,4 +54,11 @@  foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
     profopt-execute $src
 }
 
+foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
+    if ![runtest_file_p $runtests $src] then {
+        continue
+    }
+    auto-profopt-execute $src
+}
+
 set PROFOPT_OPTIONS $treeprof_save_profopt_options
diff --git a/gcc/testsuite/gcc.misc-tests/bprob.exp b/gcc/testsuite/gcc.misc-tests/bprob.exp
index 52dcb1f..132bfe3 100644
--- a/gcc/testsuite/gcc.misc-tests/bprob.exp
+++ b/gcc/testsuite/gcc.misc-tests/bprob.exp
@@ -41,6 +41,7 @@  load_lib profopt.exp
 set bprob_save_profopt_options $PROFOPT_OPTIONS
 set PROFOPT_OPTIONS [list { -O2 } { -O3  }]
 
+set profile_wrapper ""
 set profile_options "-fprofile-arcs"
 set feedback_options "-fbranch-probabilities"
 
@@ -54,4 +55,10 @@  foreach profile_option $profile_options feedback_option $feedback_options {
     }
 }
 
+foreach src [lsort [glob -nocomplain $srcdir/$subdir/bprob-*.c]] {
+    if ![runtest_file_p $runtests $src] then {
+        continue
+    }
+    auto-profopt-execute $src
+}
 set PROFOPT_OPTIONS $bprob_save_profopt_options
diff --git a/gcc/testsuite/gfortran.dg/prof/prof.exp b/gcc/testsuite/gfortran.dg/prof/prof.exp
index 0bad01d..acc8ed0 100644
--- a/gcc/testsuite/gfortran.dg/prof/prof.exp
+++ b/gcc/testsuite/gfortran.dg/prof/prof.exp
@@ -53,4 +53,11 @@  foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.f*]] {
     profopt-execute $src
 }
 
+foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.f*]] {
+    if ![runtest_file_p $runtests $src] then {
+        continue
+    }
+    auto-profopt-execute $src
+}
+
 set PROFOPT_OPTIONS $treeprof_save_profopt_options
diff --git a/gcc/testsuite/lib/profopt.exp b/gcc/testsuite/lib/profopt.exp
index 0aea6c4..b3e2b2e 100644
--- a/gcc/testsuite/lib/profopt.exp
+++ b/gcc/testsuite/lib/profopt.exp
@@ -36,7 +36,7 @@  load_lib gcc-dg.exp
 global PROFOPT_OPTIONS perf_delta
 
 # The including .exp file must define these.
-global tool profile_option feedback_option prof_ext
+global tool profile_option feedback_option prof_ext profile_wrapper
 if ![info exists tool] {
     error "Tools is not specified."
 }
@@ -229,6 +229,31 @@  proc profopt-get-options { src } {
     return ${dg-extra-tool-flags}
 }
 
+# auto-profopt-execute -- Compile for auto profiling and then feedback,
+# then normal. SRC is the full path name of the testcase.
+proc auto-profopt-execute { src } {
+    global profile_wrapper
+    global profile_option
+    global feedback_option
+    global run_autofdo
+    global srcdir
+
+    if { ! [check_profiling_available "-fauto-profile"] } {
+        regsub "(?q)$srcdir/" $src "" testcase
+        unsupported "$testcase"
+        return
+    }
+    set profile_wrapper [profopt-perf-wrapper]
+    set profile_option "-g"
+    set feedback_option "-fauto-profile"
+    set run_autofdo 1
+    profopt-execute $src
+    unset profile_wrapper
+    unset profile_option
+    unset feedback_option
+    unset run_autofdo
+}
+
 #
 # c-prof-execute -- compile for profiling and then feedback, then normal
 #
@@ -238,6 +263,7 @@  proc profopt-execute { src } {
     global srcdir tmpdir
     global PROFOPT_OPTIONS
     global tool profile_option feedback_option prof_ext perf_ext perf_delta
+    global profile_wrapper run_autofdo ld_library_path
     global generate_final_code use_final_code
     global verbose
     global testname_with_flags
@@ -248,6 +274,12 @@  proc profopt-execute { src } {
     if ![info exists feedback_option] {
         error "No feedback option specified for second compile."
     }
+    if ![info exists profile_wrapper] {
+	set profile_wrapper ""
+    }
+    if ![info exists run_autofdo] {
+	set run_autofdo ""
+    }
 
     # Use the default option list or one defined for a set of tests.
     if ![info exists PROFOPT_OPTIONS] {
@@ -313,6 +345,7 @@  proc profopt-execute { src } {
 	# valid, by running it after dg-additional-files-options.
 	foreach ext $prof_ext {
 	    profopt-target-cleanup $tmpdir $base $ext
+	    profopt-target-cleanup $tmpdir perf data
 	}
 
 	# Tree profiling requires TLS runtime support, which may need
@@ -335,12 +368,50 @@  proc profopt-execute { src } {
 	}
 
 	# Run the profiled test.
+	if { $run_autofdo == 1 } {
+	    if { ![info exists ld_library_path]} {
+		set ld_library_path ""
+	    }
+	    set orig_ld_library_path "[getenv LD_LIBRARY_PATH]"
+	    setenv LD_LIBRARY_PATH "$ld_library_path:$orig_ld_library_path"
+	    verbose "Running $profile_wrapper $execname1"
+	    set id [remote_spawn "" "$profile_wrapper $execname1" "readonly"]
+	    setenv LD_LIBRARY_PATH $orig_ld_library_path
+	    if { $id < 0 } {
+		warning "Failed to run profiler"
+		set status "fail"
+	    } else {
+		set result [remote_wait "" 300]
+		set status [lindex $result 0]
+		verbose "perf result $result"
+		if { $status == 0 } {
+		    set status "pass"
+		} else {
+		    set status "fail"
+		}
+	    }
+	} else {
+	    set result [${tool}_load $execname1 "" ""]
+	    set status [lindex $result 0]
+	}
 
-	set result [${tool}_load $execname1 "" ""]
-	set status [lindex $result 0]
 	set missing_file 0
 	# Make sure the profile data was generated, and fail if not.
 	if { $status == "pass" } {
+	    # convert profile
+	    if { $run_autofdo == 1 } {
+		set cmd "create_gcov --binary $execname1 --profile=perf.data -gcov_version=1 --gcov=$tmpdir/$base.$ext"
+		verbose "Running $cmd"
+		set id [remote_spawn "" $cmd]
+		if { $id < 0 } {
+		    unsupported "$testcase: Cannot run $cmd"
+		    set status "fail"
+		    return
+		}
+		set status [remote_wait "" 300]
+		set status "pass"
+	    }
+
 	    foreach ext $prof_ext {
 		remote_upload target $tmpdir/$base.$ext
 		set files [glob -nocomplain $base.$ext]
@@ -375,6 +446,10 @@  proc profopt-execute { src } {
 	set options "$extra_options"
 	lappend options "additional_flags=$option $extra_flags $feedback_option"
 	set optstr "$option $feedback_option"
+	if { [string first "-fauto-profile" $options] >= 0} {
+	    set options [regsub -- "-fauto-profile" $options "-fauto-profile=$tmpdir/$base.$ext"]
+	}
+
 	set comp_output [${tool}_target_compile "$src" "$execname2" "executable" $options]
 
 	# Prune warnings we know are unwanted.
@@ -399,6 +474,7 @@  proc profopt-execute { src } {
 	# Remove the profiling data files.
 	foreach ext $prof_ext {
 	    profopt-target-cleanup $tmpdir $base $ext
+	    profopt-target-cleanup $tmpdir perf data
 	}
 
 	if { $status != "pass" } {
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 1b1d03a..62267cf 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -508,6 +508,13 @@  proc check_effective_target_keeps_null_pointer_checks { } {
     return 0
 }
 
+# Return the autofdo profile wrapper
+
+proc profopt-perf-wrapper { } {
+    global srcdir
+    return "$srcdir/../config/i386/gcc-auto-profile -o perf.data "
+}
+
 # Return true if profiling is supported on the target.
 
 proc check_profiling_available { test_what } {
@@ -525,6 +532,36 @@  proc check_profiling_available { test_what } {
 	}
     }
 
+    if { $test_what == "-fauto-profile" } {
+	if { ! ([istarget x86_64-*-linux*] || [istarget i?86-*-linux*]) } {
+            verbose "autofdo only supported on linux"
+            return 0
+        }
+	# not cross compiling?
+	if { ![isnative] } {
+	    verbose "autofdo not supported for non native builds"
+	    return 0
+	}
+	set event [profopt-perf-wrapper]
+	if {$event == "" } {
+	    verbose "autofdo not supported"
+	    return 0
+	}
+        global srcdir
+	set status [remote_exec host "$srcdir/../config/i386/gcc-auto-profile" "true -v >/dev/null"]
+	if { [lindex $status 0] != 0 } {
+	    verbose "autofdo not supported because perf does not work"
+	    return 0
+	}
+
+	# no good way to check this in advance -- check later instead.
+	#set status [remote_exec host "create_gcov" "2>/dev/null"]
+	#if { [lindex $status 0] != 255 } {
+        #    verbose "autofdo not supported due to missing create_gcov"
+        #    return 0
+        #}
+    }
+
     # Support for -p on solaris2 relies on mcrt1.o which comes with the
     # vendor compiler.  We cannot reliably predict the directory where the
     # vendor compiler (and thus mcrt1.o) is installed so we can't