From: Andrew Pinski <pinskia@gcc.gnu.org>
To: Philipp Tomsich <philipp.tomsich@vrull.eu>
Cc: gcc-patches@gcc.gnu.org,
Thiago Jung Bauermann <thiago.bauermann@linaro.org>,
Tamar Christina <Tamar.Christina@arm.com>,
Jakub Jelinek <jakub@gcc.gnu.org>,
Richard Biener <rguenth@gcc.gnu.org>,
Sergei Trofimovich <slyfox@gcc.gnu.org>,
Tobian Burnus <burnus@gcc.gnu.org>, Jeff Law <law@gcc.gnu.org>,
Kito Cheng <kito.cheng@gmail.com>,
Manolis Tsamis <manolis.tsamis@vrull.eu>
Subject: Re: [PATCH] cprop_hardreg: fix ORIGINAL_REGNO/REG_ATTRS/REG_POINTER handling
Date: Thu, 22 Jun 2023 21:08:08 -0700 [thread overview]
Message-ID: <CA+=Sn1mu9Vw+aqU9_WRqft3fDb_JYD-tWdbuLVjVF7+L6_A-wQ@mail.gmail.com> (raw)
In-Reply-To: <20230622111154.2837175-1-philipp.tomsich@vrull.eu>
On Thu, Jun 22, 2023 at 4:12 AM Philipp Tomsich
<philipp.tomsich@vrull.eu> wrote:
>
> From: Manolis Tsamis <manolis.tsamis@vrull.eu>
>
> Fixes: 6a2e8dcbbd4bab3
>
> Propagation for the stack pointer in regcprop was enabled in
> 6a2e8dcbbd4bab3, but set ORIGINAL_REGNO/REG_ATTRS/REG_POINTER for
> stack_pointer_rtx which caused regression (e.g., PR 110313, PR 110308).
>
> This fix adds special handling for stack_pointer_rtx in the places
> where maybe_mode_change is called. This also adds an check in
> maybe_mode_change to return the stack pointer only when the requested
> mode matches the mode of stack_pointer_rtx.
The only comment I have is on the testcase.
>
> PR 110308
>
> gcc/ChangeLog:
>
> * regcprop.cc (maybe_mode_change): Check stack_pointer_rtx mode.
> (find_oldest_value_reg): Special handling of stack_pointer_rtx.
> (copyprop_hardreg_forward_1): Ditto.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/torture/pr110308.C: New test.
>
> Signed-off-by: Manolis Tsamis <manolis.tsamis@vrull.eu>
> Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
>
> ---
> This addresses both the PRs (110308 and 110313) and was confirmed to
> resolve the AArch64 bootstrap issue reported by Thiago.
>
> OK for trunk?
>
> gcc/regcprop.cc | 43 +++++++++++++++++--------
> gcc/testsuite/g++.dg/torture/pr110308.C | 30 +++++++++++++++++
> 2 files changed, 60 insertions(+), 13 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/torture/pr110308.C
>
> diff --git a/gcc/regcprop.cc b/gcc/regcprop.cc
> index 6cbfadb181f..fe75b7f1fa0 100644
> --- a/gcc/regcprop.cc
> +++ b/gcc/regcprop.cc
> @@ -423,7 +423,7 @@ maybe_mode_change (machine_mode orig_mode, machine_mode copy_mode,
> It's unclear if we need to do the same for other special registers. */
> if (regno == STACK_POINTER_REGNUM)
> {
> - if (orig_mode == new_mode)
> + if (orig_mode == new_mode && new_mode == GET_MODE (stack_pointer_rtx))
> return stack_pointer_rtx;
> else
> return NULL_RTX;
> @@ -487,9 +487,14 @@ find_oldest_value_reg (enum reg_class cl, rtx reg, struct value_data *vd)
> new_rtx = maybe_mode_change (oldmode, vd->e[regno].mode, mode, i, regno);
> if (new_rtx)
> {
> - ORIGINAL_REGNO (new_rtx) = ORIGINAL_REGNO (reg);
> - REG_ATTRS (new_rtx) = REG_ATTRS (reg);
> - REG_POINTER (new_rtx) = REG_POINTER (reg);
> + if (new_rtx != stack_pointer_rtx)
> + {
> + ORIGINAL_REGNO (new_rtx) = ORIGINAL_REGNO (reg);
> + REG_ATTRS (new_rtx) = REG_ATTRS (reg);
> + REG_POINTER (new_rtx) = REG_POINTER (reg);
> + }
> + else if (REG_POINTER (new_rtx) != REG_POINTER (reg))
> + return NULL_RTX;
> return new_rtx;
> }
> }
> @@ -965,15 +970,27 @@ copyprop_hardreg_forward_1 (basic_block bb, struct value_data *vd)
>
> if (validate_change (insn, &SET_SRC (set), new_rtx, 0))
> {
> - ORIGINAL_REGNO (new_rtx) = ORIGINAL_REGNO (src);
> - REG_ATTRS (new_rtx) = REG_ATTRS (src);
> - REG_POINTER (new_rtx) = REG_POINTER (src);
> - if (dump_file)
> - fprintf (dump_file,
> - "insn %u: replaced reg %u with %u\n",
> - INSN_UID (insn), regno, REGNO (new_rtx));
> - changed = true;
> - goto did_replacement;
> + bool can_change;
> + if (new_rtx != stack_pointer_rtx)
> + {
> + ORIGINAL_REGNO (new_rtx) = ORIGINAL_REGNO (src);
> + REG_ATTRS (new_rtx) = REG_ATTRS (src);
> + REG_POINTER (new_rtx) = REG_POINTER (src);
> + can_change = true;
> + }
> + else
> + can_change
> + = (REG_POINTER (new_rtx) == REG_POINTER (src));
> +
> + if (can_change)
> + {
> + if (dump_file)
> + fprintf (dump_file,
> + "insn %u: replaced reg %u with %u\n",
> + INSN_UID (insn), regno, REGNO (new_rtx));
> + changed = true;
> + goto did_replacement;
> + }
> }
> /* We need to re-extract as validate_change clobbers
> recog_data. */
> diff --git a/gcc/testsuite/g++.dg/torture/pr110308.C b/gcc/testsuite/g++.dg/torture/pr110308.C
> new file mode 100644
> index 00000000000..ddd30d4fc3f
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/torture/pr110308.C
> @@ -0,0 +1,30 @@
> +/* { dg-do compile } */
> +/* { dg-options "-g2 -O2" } */
Since this is in `g++.dg/torture`, you don't need dg-options as the
DG_TORTURE_OPTIONS includes `-O3 -g` already (note `-g` is the same as
`-g2`).
Thanks,
Andrew
> +
> +int channelCount, decodeBlock_outputLength;
> +struct BlockCodec {
> + virtual int decodeBlock(const unsigned char *, short *);
> +};
> +struct ms_adpcm_state {
> + char predictorIndex;
> + int sample1;
> + ms_adpcm_state();
> +};
> +bool decodeBlock_ok;
> +void encodeBlock() { ms_adpcm_state(); }
> +struct MSADPCM : BlockCodec {
> + int decodeBlock(const unsigned char *, short *);
> +};
> +void decodeSample(ms_adpcm_state, bool *);
> +int MSADPCM::decodeBlock(const unsigned char *, short *) {
> + ms_adpcm_state decoderState[2];
> + ms_adpcm_state *state[2];
> + state[0] = &decoderState[0];
> + if (channelCount == 2)
> + state[1] = &decoderState[0];
> + short m_coefficients[state[1]->predictorIndex];
> + for (int i = 0; i < channelCount; i++)
> + ++state[i]->sample1;
> + decodeSample(*state[1], &decodeBlock_ok);
> + return decodeBlock_outputLength;
> +}
> \ No newline at end of file
> --
> 2.34.1
>
next prev parent reply other threads:[~2023-06-23 4:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-22 11:11 Philipp Tomsich
2023-06-23 4:08 ` Andrew Pinski [this message]
2023-06-25 13:09 ` Jeff Law
2023-06-28 14:10 ` Philipp Tomsich
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='CA+=Sn1mu9Vw+aqU9_WRqft3fDb_JYD-tWdbuLVjVF7+L6_A-wQ@mail.gmail.com' \
--to=pinskia@gcc.gnu.org \
--cc=Tamar.Christina@arm.com \
--cc=burnus@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@gcc.gnu.org \
--cc=kito.cheng@gmail.com \
--cc=law@gcc.gnu.org \
--cc=manolis.tsamis@vrull.eu \
--cc=philipp.tomsich@vrull.eu \
--cc=rguenth@gcc.gnu.org \
--cc=slyfox@gcc.gnu.org \
--cc=thiago.bauermann@linaro.org \
/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).