From: Alexander Monakov <amonakov@ispras.ru>
To: "Jose E. Marchesi" <jose.marchesi@oracle.com>
Cc: gcc-patches@gcc.gnu.org, qing.zhao@oracle.com
Subject: Re: [PATCH V2] Disable sched1 in functions that call setjmp
Date: Thu, 22 Dec 2022 20:56:18 +0300 (MSK) [thread overview]
Message-ID: <53b93d7e-a157-9116-d07a-4d51cd43d205@ispras.ru> (raw)
In-Reply-To: <20221222173208.13317-1-jose.marchesi@oracle.com>
On Thu, 22 Dec 2022, Jose E. Marchesi via Gcc-patches wrote:
> The first instruction scheduler pass reorders instructions in the TRY
> block in a way `b=true' gets executed before the call to the function
> `f'. This optimization is wrong, because `main' calls setjmp and `f'
> is known to call longjmp.
>
> As discussed in BZ 57067, the root cause for this is the fact that
> setjmp is not properly modeled in RTL, and therefore the backend
> passes have no normalized way to handle this situation.
>
> As Alexander Monakov noted in the BZ, many RTL passes refuse to touch
> functions that call setjmp. This includes for example gcse,
> store_motion and cprop. This patch adds the sched1 pass to that list.
>
> Note that the other instruction scheduling passes are still allowed to
> run on these functions, since they reorder instructions within basic
> blocks, and therefore they cannot cross function calls.
>
> This doesn't fix the fundamental issue, but at least assures that
> sched1 wont perform invalid transformation in correct C programs.
I think scheduling across calls in the pre-RA scheduler is simply an oversight,
we do not look at dataflow information and with 50% chance risk extending
lifetime of a pseudoregister across a call, causing higher register pressure at
the point of the call, and potentially an extra spill.
Therefore I would suggest to indeed solve the root cause, with (untested):
diff --git a/gcc/sched-deps.cc b/gcc/sched-deps.cc
index 948aa0c3b..343fe2bfa 100644
--- a/gcc/sched-deps.cc
+++ b/gcc/sched-deps.cc
@@ -3688,7 +3688,13 @@ 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)
+ {
+ /* Do not schedule across calls, this is prone to extending lifetime
+ of a pseudo and causing extra spill later on. */
+ 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. */
Alexander
next prev parent reply other threads:[~2022-12-22 17:56 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-22 17:32 Jose E. Marchesi
2022-12-22 17:56 ` Alexander Monakov [this message]
2022-12-22 19:28 ` Qing Zhao
2022-12-23 7:33 ` Alexander Monakov
2022-12-23 14:34 ` Qing Zhao
2022-12-23 15:03 ` Alexander Monakov
2022-12-23 17:27 ` Jose E. Marchesi
2022-12-23 17:31 ` Alexander Monakov
2022-12-23 17:45 ` Jose E. Marchesi
2022-12-23 19:21 ` Qing Zhao
2022-12-23 19:36 ` Alexander Monakov
2022-12-23 19:57 ` Qing Zhao
2022-12-24 8:10 ` Alexander Monakov
2022-12-24 9:26 ` Richard Biener
2022-12-24 9:58 ` Jose E. Marchesi
2022-12-24 10:06 ` Richard Biener
2022-12-24 10:18 ` Alexander Monakov
2022-12-26 0:29 ` Segher Boessenkool
2023-01-05 18:11 ` Qing Zhao
2022-12-23 10:05 ` Richard Sandiford
2022-12-23 10:42 ` Jose E. Marchesi
2023-01-13 18:20 ` [PATCH] sched-deps: do not schedule pseudos across calls [PR108117] Alexander Monakov
2023-01-13 18:23 ` Richard Sandiford
2023-01-13 18:33 ` Jose E. Marchesi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53b93d7e-a157-9116-d07a-4d51cd43d205@ispras.ru \
--to=amonakov@ispras.ru \
--cc=gcc-patches@gcc.gnu.org \
--cc=jose.marchesi@oracle.com \
--cc=qing.zhao@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).