From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 0B0A13886C5D for ; Mon, 2 Aug 2021 09:57:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0B0A13886C5D Received: by mail-ed1-x52b.google.com with SMTP id cf5so12123390edb.2 for ; Mon, 02 Aug 2021 02:57:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7g2Z9JUcuET1J0OwYZf26822JHFDomPgtAz58ee/eP4=; b=jusl6BZcC8AWQX0kiThLbz34KqnBzl4dIXZDcdFkB+otLT0V1lJM3v4cYXp9KUs1CG b5lVc4CRupUX4O2mHPPjU8kxWCV0bzQH26xZHwFh+Txv2UHjKlql22OOd8LhrBMOEbhe N3S46YbKhGcTQQ4MK0QSmwCaMzv+eEUDJ0+YnMas9lCxSTVqJ7DbcgfZmNEpcjkDVRSo Of/Pwfhk8zDwv0jUfByNEHAHMkv2fr9DaZbSfZhrnC884EJ/g0uCoWAPKXARVT1Mfx8a oc00C4BbuxblUEeIBUgoPbUTJosjf/DVlnZ/UIWVZRAtB/eME/IMQuFDxQKuk/sXTeE7 HUTg== X-Gm-Message-State: AOAM533VhubpuLTz2f6C7smvcG/3VPHWBa4F7Vi5ydC0lAvdqrPTmnnm jzEEOhVrWTBHuq/NrPMTowQ2XqB53fwr+wSeYF0= X-Google-Smtp-Source: ABdhPJxARR7nzalihiyrzYmi6sjd0ZuQswHnjpI+i3VmzfHDhPpApMr/SqVTn7sY1pAuFaoDLKnG1HsohUtWAwccNgE= X-Received: by 2002:aa7:d541:: with SMTP id u1mr3530536edr.138.1627898221098; Mon, 02 Aug 2021 02:57:01 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Mon, 2 Aug 2021 11:56:50 +0200 Message-ID: Subject: Re: [PATCH] gcov-profile/71672 Fix indirect call inlining with AutoFDO To: Eugene Rozenfeld Cc: "gcc-patches@gcc.gnu.org" , "mliska@suse.cz" , Andi Kleen Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Aug 2021 09:57:04 -0000 On Fri, Jul 30, 2021 at 9:09 AM Eugene Rozenfeld via Gcc-patches wrote: > > This patch has the following changes: > > 1. The main fix is in auto-profile.c: the histogram value for > indirect calls was incorrectly set up. That is fixed now. > > 2. Several tests now have -fdump-ipa-afdo-optimized instead of -fdump-ipa-afdo > in dg-options so that the expected output can be found. > > 3. I increased the number of iterations in several tests so that perf can have > enough sampling events. > > 4. indir-call-prof-2.c has -fno-early-inlining but AutoFDO can't work without > early inlining (it needs to match the inlining of the profiled binary). > I changed profopt.exp to always pass -fearly-inlining for AutoFDO. > With that the indirect call inlining in indir-call-prof-2.c happens in the early inliner > so I changed the dg-final-use-autofdo. > > 5. create_gcov tool doesn't currently support dwarf 5 so I made a change in profopt.exp > to pass -gdwarf-4 when compiling the binary to profile. > > 6. I updated the invocation of create_gcov in profopt.exp to pass -gcov_version=2. > I recently made a change to create_gcov to support version 2: > https://github.com/google/autofdo/pull/117 > > 7. I removed useless -o perf.data from the invocation of gcc-auto-profile in > target-supports.exp. > > With these changes the tests checking indirect call inlining in gcc.dg and g++.dg > are passing. OK. Thanks, Richard. > gcc/ChangeLog: > PR gcov-profile/71672 > * auto-profile.c (afdo_indirect_call): Fix the setup of the historgram value for indirect calls. > > gcc/testsuite/ChangeLog: > PR gcov-profile/71672 > * g++.dg/tree-prof/indir-call-prof.C: Fix options, increase the number of iterations. > * g++.dg/tree-prof/morefunc.C: Fix options, increase the number of iterations. > * g++.dg/tree-prof/reorder.C: Fix options, increase the number of iterations. > * gcc.dg/tree-prof/indir-call-prof-2.c: Fix options, fix dg-final-use-autofdo, increase the number of iterations. > * gcc.dg/tree-prof/indir-call-prof.c: Fix options. > * lib/profopt.exp: Pass gdwarf-4 when compiling binary to profile; pass -fearly-inlining when compiling with AutoFDO; pass -gcov_version=2 to create_gcov. > * lib/target-supports.exp: Remove unnecessary -o perf.data passed to gcc-auto-profile. > --- > gcc/auto-profile.c | 13 +++++++++---- > gcc/testsuite/g++.dg/tree-prof/indir-call-prof.C | 4 ++-- > gcc/testsuite/g++.dg/tree-prof/morefunc.C | 7 ++++--- > gcc/testsuite/g++.dg/tree-prof/reorder.C | 6 +++--- > gcc/testsuite/gcc.dg/tree-prof/indir-call-prof-2.c | 8 ++++---- > gcc/testsuite/gcc.dg/tree-prof/indir-call-prof.c | 2 +- > gcc/testsuite/lib/profopt.exp | 6 +++--- > gcc/testsuite/lib/target-supports.exp | 2 +- > 8 files changed, 27 insertions(+), 21 deletions(-) > > diff --git a/gcc/auto-profile.c b/gcc/auto-profile.c > index b23b82b2df4..4c1fc6b536b 100644 > --- a/gcc/auto-profile.c > +++ b/gcc/auto-profile.c > @@ -1009,13 +1009,18 @@ afdo_indirect_call (gimple_stmt_iterator *gsi, const icall_target_map &map, > > histogram_value hist = gimple_alloc_histogram_value ( > cfun, HIST_TYPE_INDIR_CALL, stmt, callee); > - hist->n_counters = 3; > + hist->n_counters = 4; > hist->hvalue.counters = XNEWVEC (gcov_type, hist->n_counters); > gimple_add_histogram_value (cfun, stmt, hist); > > - hist->hvalue.counters[0] = direct_call->profile_id; > - hist->hvalue.counters[1] = max_iter->second; > - hist->hvalue.counters[2] = total; > + // Total counter > + hist->hvalue.counters[0] = total; > + // Number of value/counter pairs > + hist->hvalue.counters[1] = 1; > + // Value > + hist->hvalue.counters[2] = direct_call->profile_id; > + // Counter > + hist->hvalue.counters[3] = max_iter->second; > > if (!transform) > return; > diff --git a/gcc/testsuite/g++.dg/tree-prof/indir-call-prof.C b/gcc/testsuite/g++.dg/tree-prof/indir-call-prof.C > index 3374744613e..b45417106d0 100644 > --- a/gcc/testsuite/g++.dg/tree-prof/indir-call-prof.C > +++ b/gcc/testsuite/g++.dg/tree-prof/indir-call-prof.C > @@ -1,4 +1,4 @@ > -/* { dg-options "-O2 -fdump-tree-optimized -fdump-ipa-profile-optimized -fdump-ipa-afdo" } */ > +/* { dg-options "-O2 -fdump-tree-optimized -fdump-ipa-profile-optimized -fdump-ipa-afdo-optimized" } */ > > struct A { > A () {} > @@ -26,7 +26,7 @@ main (void) > > int i; > > - for (i = 0; i < 1000000; i++) > + for (i = 0; i < 10000000; i++) > { > p = (A *)wrap ((void *)&a); > p->AA (); > diff --git a/gcc/testsuite/g++.dg/tree-prof/morefunc.C b/gcc/testsuite/g++.dg/tree-prof/morefunc.C > index 621d09aec5b..96e0073ca8f 100644 > --- a/gcc/testsuite/g++.dg/tree-prof/morefunc.C > +++ b/gcc/testsuite/g++.dg/tree-prof/morefunc.C > @@ -1,4 +1,5 @@ > -/* { dg-options "-O2 -fno-devirtualize --param=profile-func-internal-id=0 -fdump-ipa-profile-optimized -fdump-ipa-afdo -Wno-attributes -Wno-coverage-mismatch -Wno-missing-profile" } */ > +/* { dg-options "-O2 -fno-devirtualize --param=profile-func-internal-id=0 -fdump-ipa-profile-optimized -fdump-ipa-afdo-optimized -Wno-attributes -Wno-coverage-mismatch -Wno-missing-profile" } */ > + > #include "reorder_class1.h" > #include "reorder_class2.h" > > @@ -19,7 +20,7 @@ static __attribute__((always_inline)) > void test1 (A *tc) > { > int i; > - for (i = 0; i < 1000; i++) > + for (i = 0; i < 10000000; i++) > g += tc->foo(); > if (g<100) g++; > } > @@ -28,7 +29,7 @@ static __attribute__((always_inline)) > void test2 (B *tc) > { > int i; > - for (i = 0; i < 1000000; i++) > + for (i = 0; i < 10000000; i++) > g += tc->foo(); > } > > diff --git a/gcc/testsuite/g++.dg/tree-prof/reorder.C b/gcc/testsuite/g++.dg/tree-prof/reorder.C > index 000fb651a69..50490963369 100644 > --- a/gcc/testsuite/g++.dg/tree-prof/reorder.C > +++ b/gcc/testsuite/g++.dg/tree-prof/reorder.C > @@ -1,4 +1,4 @@ > -/* { dg-options "-O2 -fno-devirtualize --param=profile-func-internal-id=0 -fdump-ipa-profile-optimized -fdump-ipa-afdo -Wno-coverage-mismatch -Wno-attributes" } */ > +/* { dg-options "-O2 -fno-devirtualize --param=profile-func-internal-id=0 -fdump-ipa-profile-optimized -fdump-ipa-afdo-optimized -Wno-coverage-mismatch -Wno-attributes" } */ > > #ifdef _PROFILE_USE > #include "reorder_class1.h" > @@ -13,7 +13,7 @@ static __attribute__((always_inline)) > void test1 (A *tc) > { > int i; > - for (i = 0; i < 1000000; i++) > + for (i = 0; i < 10000000; i++) > g += tc->foo(); > if (g<100) g++; > } > @@ -22,7 +22,7 @@ static __attribute__((always_inline)) > void test2 (B *tc) > { > int i; > - for (i = 0; i < 1000000; i++) > + for (i = 0; i < 10000000; i++) > g += tc->foo(); > } > > diff --git a/gcc/testsuite/gcc.dg/tree-prof/indir-call-prof-2.c b/gcc/testsuite/gcc.dg/tree-prof/indir-call-prof-2.c > index bbba0521018..594c3f34d57 100644 > --- a/gcc/testsuite/gcc.dg/tree-prof/indir-call-prof-2.c > +++ b/gcc/testsuite/gcc.dg/tree-prof/indir-call-prof-2.c > @@ -1,4 +1,4 @@ > -/* { dg-options "-O2 -fno-early-inlining -fdump-ipa-profile-optimized -fdump-ipa-afdo" } */ > +/* { dg-options "-O2 -fno-early-inlining -fdump-ipa-profile-optimized -fdump-tree-einline-optimized" } */ > volatile int one; > static int > add1 (int val) > @@ -22,7 +22,7 @@ int > main (void) > { > int i, val = 0; > - for (i = 0; i < 100000; i++) > + for (i = 0; i < 10000000; i++) > { > val = do_op (val, add1); > val = do_op (val, sub1); > @@ -31,5 +31,5 @@ main (void) > } > /* { dg-final-use-not-autofdo { scan-ipa-dump "Indirect call -> direct call.* add1 .will resolve by ipa-profile" "profile"} } */ > /* { dg-final-use-not-autofdo { scan-ipa-dump "Indirect call -> direct call.* sub1 .will resolve by ipa-profile" "profile"} } */ > -/* { dg-final-use-autofdo { scan-ipa-dump "Indirect call -> direct call.* add1 .will resolve by ipa-profile" "afdo"} } */ > -/* { dg-final-use-autofdo { scan-ipa-dump "Indirect call -> direct call.* sub1 .will resolve by ipa-profile" "afdo"} } */ > +/* { dg-final-use-autofdo { scan-tree-dump "Inlining add1/1 into main/4." "einline"} } */ > +/* { dg-final-use-autofdo { scan-tree-dump "Inlining sub1/2 into main/4." "einline"} } */ > diff --git a/gcc/testsuite/gcc.dg/tree-prof/indir-call-prof.c b/gcc/testsuite/gcc.dg/tree-prof/indir-call-prof.c > index 138b85a08d2..702045239f3 100644 > --- a/gcc/testsuite/gcc.dg/tree-prof/indir-call-prof.c > +++ b/gcc/testsuite/gcc.dg/tree-prof/indir-call-prof.c > @@ -1,4 +1,4 @@ > -/* { dg-options "-O2 -fdump-tree-optimized -fdump-ipa-profile-optimized -fdump-ipa-afdo" } */ > +/* { dg-options "-O2 -fdump-tree-optimized -fdump-ipa-profile-optimized -fdump-ipa-afdo-optimized" } */ > > static int a1 (void) > { > diff --git a/gcc/testsuite/lib/profopt.exp b/gcc/testsuite/lib/profopt.exp > index 9997eb3bb7e..25f45ecf2de 100644 > --- a/gcc/testsuite/lib/profopt.exp > +++ b/gcc/testsuite/lib/profopt.exp > @@ -289,8 +289,8 @@ proc auto-profopt-execute { src } { > return > } > set profile_wrapper [profopt-perf-wrapper] > - set profile_option "-g -DFOR_AUTOFDO_TESTING" > - set feedback_option "-fauto-profile -DFOR_AUTOFDO_TESTING" > + set profile_option "-gdwarf-4 -DFOR_AUTOFDO_TESTING" > + set feedback_option "-fauto-profile -DFOR_AUTOFDO_TESTING -fearly-inlining" > set run_autofdo 1 > profopt-execute $src > unset profile_wrapper > @@ -451,7 +451,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=1 --gcov=$tmpdir/$bprefix$base.$ext" > + set cmd "create_gcov --binary $execname1 --profile=$tmpdir/$base.perf.data -gcov_version=2 --gcov=$tmpdir/$bprefix$base.$ext" > verbose "Running $cmd" > set id [remote_spawn "" $cmd] > if { $id < 0 } { > diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp > index 789723fb287..ae22e103883 100644 > --- a/gcc/testsuite/lib/target-supports.exp > +++ b/gcc/testsuite/lib/target-supports.exp > @@ -626,7 +626,7 @@ proc check_effective_target_keeps_null_pointer_checks { } { > # this allows parallelism of 16 and higher of parallel gcc-auto-profile > proc profopt-perf-wrapper { } { > global srcdir > - return "$srcdir/../config/i386/gcc-auto-profile -o perf.data -m8 " > + return "$srcdir/../config/i386/gcc-auto-profile -m8 " > } > > # Return true if profiling is supported on the target. > -- > 2.25.1