From: Richard Biener <richard.guenther@gmail.com>
To: Roger Sayle <roger@nextmovesoftware.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [x86 PATCH] PR target/106577: force_reg may clobber operands during split.
Date: Mon, 15 Aug 2022 09:45:51 +0200 [thread overview]
Message-ID: <CAFiYyc0xK7BMJkR3xR3=Ku7_hhqyyZDEzPiWSUe2e7cYiTS2zw@mail.gmail.com> (raw)
In-Reply-To: <002201d8ae8b$d11fa9b0$735efd10$@nextmovesoftware.com>
On Fri, Aug 12, 2022 at 10:41 PM Roger Sayle <roger@nextmovesoftware.com> wrote:
>
>
> This patch fixes PR target/106577 which is a recent ICE on valid regression
> caused by my introduction of a *testti_doubleword pre-reload splitter in
> i386.md. During the split pass before reload, this converts the virtual
> *testti_doubleword into an *andti3_doubleword and *cmpti_doubleword,
> checking that any immediate operand is a valid "x86_64_hilo_general_operand"
> and placing it into a TImode register using force_reg if it isn't.
>
> The unexpected behaviour (that caught me out) is that calling force_reg
> may occasionally clobber the contents of the global operands array, or
> more accurately recog_data.operand[0], which means that by the time
> split_XXX calls gen_split_YYY the replacement insn's operands have been
> corrupted.
>
> It's difficult to tell who (if anyone is at fault). The re-entrant
> stack trace (for the attached PR) looks like:
>
> gen_split_203 (*testti_doubleword) calls
> force_reg calls
> emit_move_insn calls
> emit_move_insn_1 calls
> gen_movti calls
> ix86_expand_move calls
> ix86_convert_const_wide_int_to_broadcast calls
> ix86_vector_duplicate_value calls
> recog_memoized calls
> recog.
>
> By far the simplest and possibly correct fix is rather than attempt
> to push and pop recog_data, to simply (in pre-reload splits) save a
> copy of any operands that will be needed after force_reg, and use
> these copies afterwards. Many pre-reload splitters avoid this issue
> using "[(clobber (const_int 0))]" and so avoid gen_split_YYY functions,
> but in our case we still need to save a copy of operands[0] (even if we
> call emit_insn or expand_* ourselves), so we might as well continue to
> use the conveniently generated gen_split.
>
> This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
> and make -k check, both with and without --target_board=unix{-m32},
> with no new failures. Ok for mainline?
Why this obviously fixes the issue seen I wonder whether there's
more of recog_data that might be used after control flow returns
to recog_memoized and thus the fix would be there, not in any
backend pattern triggering the issue like this?
The "easiest" fix would maybe to add a in_recog flag and
simply return FAIL from recog when recursing. Not sure what
the effect on this particular pattern would be though?
The better(?) fix might be to push/pop recog_data in 'recog', but
of course give that recog_data is currently a global leakage
in intermediate code can still happen.
That said - does anybody know of similar fixes for this issue in other
backends patterns?
Thanks,
Richard.
>
>
> 2022-08-12 Roger Sayle <roger@nextmovesoftware.com>
>
> gcc/ChangeLog
> PR target/106577
> * config/i386/i386.md (*testti_doubleword): Preserve a copy of
> operands[0], and move initialization of operands[2] later, as the
> call to force_reg may clobber the contents of the operands array.
>
> gcc/testsuite/ChangeLog
> PR target/106577
> * gcc.target/i386/pr106577.c: New test case.
>
>
> Thanks,
> Roger
> --
>
next prev parent reply other threads:[~2022-08-15 7:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-12 20:40 Roger Sayle
2022-08-15 7:45 ` Richard Biener [this message]
2022-08-16 8:14 ` Richard Sandiford
2022-08-16 8:26 ` Richard Biener
2022-08-16 9:02 ` Richard Sandiford
2022-12-02 9:39 ` [PATCH] i386: Save/restore recog_data in ix86_vector_duplicate_value [PR106577] Jakub Jelinek
2022-12-02 9:51 ` Uros Bizjak
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='CAFiYyc0xK7BMJkR3xR3=Ku7_hhqyyZDEzPiWSUe2e7cYiTS2zw@mail.gmail.com' \
--to=richard.guenther@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=roger@nextmovesoftware.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).