From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id CD5913858C39 for ; Fri, 13 Jan 2023 18:23:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD5913858C39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4F2D6FEC; Fri, 13 Jan 2023 10:24:04 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.99.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7241D3F67D; Fri, 13 Jan 2023 10:23:21 -0800 (PST) From: Richard Sandiford To: Alexander Monakov Mail-Followup-To: Alexander Monakov ,"Jose E. Marchesi" , Alexander Monakov via Gcc-patches , qing.zhao@oracle.com, richard.sandiford@arm.com Cc: "Jose E. Marchesi" , Alexander Monakov via Gcc-patches , qing.zhao@oracle.com Subject: Re: [PATCH] sched-deps: do not schedule pseudos across calls [PR108117] References: <20221222173208.13317-1-jose.marchesi@oracle.com> <53b93d7e-a157-9116-d07a-4d51cd43d205@ispras.ru> <87h6xm1jvj.fsf@oracle.com> <0cc6e188-c64c-e8ea-83e4-1d06f5bf4f55@ispras.ru> Date: Fri, 13 Jan 2023 18:23:20 +0000 In-Reply-To: <0cc6e188-c64c-e8ea-83e4-1d06f5bf4f55@ispras.ru> (Alexander Monakov's message of "Fri, 13 Jan 2023 21:20:12 +0300 (MSK)") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-37.5 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Alexander Monakov writes: > On Fri, 23 Dec 2022, Jose E. Marchesi wrote: > >> > +1 for trying this FWIW. There's still plenty of time to try an >> > alternative solution if there are unexpected performance problems. >> >> Let me see if Alexander's patch fixes the issue at hand (it must) and >> will also do some regression testing. > > Hi, I'm not sure at which court the ball is, but in the interest at moving > things forward here's the complete patch with the testcase. OK to apply? > > ---8<--- > > From: Alexander Monakov > Date: Fri, 13 Jan 2023 21:04:02 +0300 > Subject: [PATCH] sched-deps: do not schedule pseudos across calls [PR108117] > > Scheduling across calls in the pre-RA scheduler is problematic: we do > not take liveness info into account, and are thus prone to extending > lifetime of a pseudo over the loop, requiring a callee-saved hardreg > or causing a spill. > > If current function called a setjmp, lifting an assignment over a call > may be incorrect if a longjmp would happen before the assignment. > > Thanks to Jose Marchesi for testing on AArch64. > > gcc/ChangeLog: > > PR rtl-optimization/108117 > PR rtl-optimization/108132 > * sched-deps.cc (deps_analyze_insn): Do not schedule across > calls before reload. > > gcc/testsuite/ChangeLog: > > PR rtl-optimization/108117 > PR rtl-optimization/108132 > * gcc.dg/pr108117.c: New test. OK, thanks. Richard > --- > gcc/sched-deps.cc | 9 ++++++++- > gcc/testsuite/gcc.dg/pr108117.c | 30 ++++++++++++++++++++++++++++++ > 2 files changed, 38 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/gcc.dg/pr108117.c > > diff --git a/gcc/sched-deps.cc b/gcc/sched-deps.cc > index 948aa0c3b..5dc4fa4cd 100644 > --- a/gcc/sched-deps.cc > +++ b/gcc/sched-deps.cc > @@ -3688,7 +3688,14 @@ deps_analyze_insn (class deps_desc *deps, rtx_insn *insn) > > CANT_MOVE (insn) = 1; > > - if (find_reg_note (insn, REG_SETJMP, NULL)) > + if (!reload_completed) > + { > + /* Scheduling across calls may increase register pressure by extending > + live ranges of pseudos over the call. Worse, in presence of setjmp > + it may incorrectly move up an assignment over a longjmp. */ > + reg_pending_barrier = MOVE_BARRIER; > + } > + else if (find_reg_note (insn, REG_SETJMP, NULL)) > { > /* This is setjmp. Assume that all registers, not just > hard registers, may be clobbered by this call. */ > diff --git a/gcc/testsuite/gcc.dg/pr108117.c b/gcc/testsuite/gcc.dg/pr108117.c > new file mode 100644 > index 000000000..ae151693e > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr108117.c > @@ -0,0 +1,30 @@ > +/* { dg-do run } */ > +/* { dg-require-effective-target nonlocal_goto } */ > +/* { dg-options "-O2 -fschedule-insns" } */ > + > +#include > +#include > + > +jmp_buf ex_buf; > + > +__attribute__((noipa)) > +void fn_throw(int x) > +{ > + if (x) > + longjmp(ex_buf, 1); > +} > + > +int main(void) > +{ > + int vb = 0; // NB: not volatile, not modified after setjmp > + > + if (!setjmp(ex_buf)) { > + fn_throw(1); > + vb = 1; // not reached in the abstract machine > + } > + > + if (vb) { > + printf("Failed, vb = %d!\n", vb); > + return 1; > + } > +}