From: Tamar Christina <Tamar.Christina@arm.com>
To: Jeff Law <jeffreyalaw@gmail.com>,
Andrew Pinski <pinskia@gmail.com>,
Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Cc: Manolis Tsamis <manolis.tsamis@vrull.eu>,
Philipp Tomsich <philipp.tomsich@vrull.eu>,
Richard Biener <richard.guenther@gmail.com>,
Palmer Dabbelt <palmer@rivosinc.com>,
Kito Cheng <kito.cheng@gmail.com>,
"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: RE: [PATCH 2/2] cprop_hardreg: Enable propagation of the stack pointer if possible.
Date: Tue, 20 Jun 2023 04:52:28 +0000 [thread overview]
Message-ID: <VI1PR08MB532590CC08F3A7107338799EFF5CA@VI1PR08MB5325.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <3bdd7695-ad88-d8d9-5133-05cb95623949@gmail.com>
> -----Original Message-----
> From: Jeff Law <jeffreyalaw@gmail.com>
> Sent: Tuesday, June 20, 2023 3:17 AM
> To: Andrew Pinski <pinskia@gmail.com>; Thiago Jung Bauermann
> <thiago.bauermann@linaro.org>
> Cc: Manolis Tsamis <manolis.tsamis@vrull.eu>; Philipp Tomsich
> <philipp.tomsich@vrull.eu>; Richard Biener <richard.guenther@gmail.com>;
> Palmer Dabbelt <palmer@rivosinc.com>; Kito Cheng <kito.cheng@gmail.com>;
> gcc-patches@gcc.gnu.org; Tamar Christina <Tamar.Christina@arm.com>
> Subject: Re: [PATCH 2/2] cprop_hardreg: Enable propagation of the stack
> pointer if possible.
>
>
>
> On 6/19/23 17:48, Andrew Pinski wrote:
> > On Mon, Jun 19, 2023 at 4:40 PM Andrew Pinski <pinskia@gmail.com>
> wrote:
> >>
> >> On Mon, Jun 19, 2023 at 9:58 AM Thiago Jung Bauermann via Gcc-patches
> >> <gcc-patches@gcc.gnu.org> wrote:
> >>>
> >>>
> >>> Hello Manolis,
> >>>
> >>> Philipp Tomsich <philipp.tomsich@vrull.eu> writes:
> >>>
> >>>> On Thu, 8 Jun 2023 at 00:18, Jeff Law <jeffreyalaw@gmail.com> wrote:
> >>>>>
> >>>>> On 5/25/23 06:35, Manolis Tsamis wrote:
> >>>>>> Propagation of the stack pointer in cprop_hardreg is currenty
> >>>>>> forbidden in all cases, due to maybe_mode_change returning NULL.
> >>>>>> Relax this restriction and allow propagation when no mode change is
> requested.
> >>>>>>
> >>>>>> gcc/ChangeLog:
> >>>>>>
> >>>>>> * regcprop.cc (maybe_mode_change): Enable stack pointer
> propagation.
> >>>>> Thanks for the clarification. This is OK for the trunk. It looks
> >>>>> generic enough to have value going forward now rather than waiting.
> >>>>
> >>>> Rebased, retested, and applied to trunk. Thanks!
> >>>
> >>> Our CI found a couple of tests that started failing on aarch64-linux
> >>> after this commit. I was able to confirm manually that they don't
> >>> happen in the commit immediately before this one, and also that
> >>> these failures are still present in today's trunk.
> >>>
> >>> I have testsuite logs for last good commit, first bad commit and
> >>> current trunk here:
> >>>
> >>> https://people.linaro.org/~thiago.bauermann/gcc-regression-6a2e8dcbb
> >>> d4b/
> >>>
> >>> Could you please check?
> >>>
> >>> These are the new failures:
> >>>
> >>> Running gcc:gcc.target/aarch64/aarch64.exp ...
> >>> FAIL: gcc.target/aarch64/stack-check-cfa-3.c scan-assembler-times
> >>> mov\\tx11, sp 1
> >>
> >> So for the above before this change we had:
> >> ```
> >> (insn:TI 597 596 598 2 (set (reg:DI 11 x11)
> >> (reg/f:DI 31 sp)) "stack-check-prologue-16.c":16:1 65
> {*movdi_aarch64}
> >> (nil))
> >> (insn 598 597 599 2 (set (mem:BLK (scratch) [0 A8])
> >> (unspec:BLK [
> >> (reg:DI 11 x11)
> >> (reg/f:DI 31 sp)
> >> ] UNSPEC_PRLG_STK)) "stack-check-prologue-16.c":16:1
> >> 1169 {stack_tie}
> >> (expr_list:REG_DEAD (reg:DI 11 x11)
> >> (nil)))
> >> ```
> >>
> >> After we get:
> >> ```
> >> (insn 598 596 599 2 (set (mem:BLK (scratch) [0 A8])
> >> (unspec:BLK [
> >> (reg:DI 31 sp [11]) repeated x2
> >> ] UNSPEC_PRLG_STK)) "stack-check-prologue-16.c":16:1
> >> 1169 {stack_tie}
> >> (nil))
> >> ```
> >> Which seems to be ok, except we still have:
> >> .cfi_def_cfa_register 11
> >>
> >> That is because on:
> >> (insn/f 596 595 598 2 (set (reg:DI 12 x12)
> >> (plus:DI (reg:DI 12 x12)
> >> (const_int 272 [0x110])))
> >> "stack-check-prologue-16.c":16:1
> >> 153 {*adddi3_aarch64}
> >> (expr_list:REG_CFA_DEF_CFA (reg:DI 11 x11)
> >> (nil)))
> >>
> >> We record x11 but never update it though that came before the mov for
> >> x11 ... So it seems like cprop_hardreg had no idea it needed to
> >> update it.
> >>
> >> I suspect the other testcases are just propagation of sp into the
> >> stores and such and just needed update. But the above testcase seems
> >> getting broken cfi though I don't know how to fix it.
Yeah, we noticed the failures internally but left them broken since we have an
upcoming AArch64 patch which requires them to be updated anyway and are
rolling up the updates into that patch.
> >
> > The code from aarch64.cc:
> > ```
> > /* This is done to provide unwinding information for the stack
> > adjustments we're about to do, however to prevent the optimizers
> > from removing the R11 move and leaving the CFA note (which would
> be
> > very wrong) we tie the old and new stack pointer together.
> > The tie will expand to nothing but the optimizers will not touch
> > the instruction. */
> > rtx stack_ptr_copy = gen_rtx_REG (Pmode,
> STACK_CLASH_SVE_CFA_REGNUM);
> > emit_move_insn (stack_ptr_copy, stack_pointer_rtx);
> > emit_insn (gen_stack_tie (stack_ptr_copy,
> > stack_pointer_rtx));
> >
> > /* We want the CFA independent of the stack pointer for the
> > duration of the loop. */
> > add_reg_note (insn, REG_CFA_DEF_CFA, stack_ptr_copy);
> > RTX_FRAME_RELATED_P (insn) = 1; ```
> >
> > Well except now with this change, the optimizers touch this
> > instruction. Maybe the move instruction should not be a move but an
> > unspec so optimizers don't know what the move was.
> > Adding Tamar to the CC who added this code to aarch64 originally for
> > comments on the above understanding here.
> It's a bit hackish, but could we reject the stack pointer for operand1 in the
> stack-tie? And if we do so, does it help?
Yeah this one I had to defer until later this week to look at closer because what I'm
wondering about is whether the optimization should apply to frame related
RTX as well.
Looking at the description of RTX_FRAME_RELATED_P that this optimization may
end up de-optimizing RISC targets by creating an offset that is larger than offset
which can be used from a SP making reload having to spill. i.e. sometimes the
move was explicitly done. So perhaps it should not apply it to
RTX_FRAME_RELATED_P in find_oldest_value_reg and copyprop_hardreg_forward_1?
Other parts of this pass already seems to bail out in similar situations. So I needed to
write some testcases to check what would happen in these cases hence the deferral.
to later in the week.
Kind Regards,
Tamar
>
> jeff
next prev parent reply other threads:[~2023-06-20 4:52 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-25 12:35 [PATCH 0/2] RISC-V: New pass to optimize calculation of offsets for memory operations Manolis Tsamis
2023-05-25 12:35 ` [PATCH 1/2] Implementation of new RISCV optimizations pass: fold-mem-offsets Manolis Tsamis
2023-05-25 13:01 ` Richard Biener
2023-05-25 13:25 ` Manolis Tsamis
2023-05-25 13:31 ` Jeff Law
2023-05-25 13:50 ` Richard Biener
2023-05-25 14:02 ` Manolis Tsamis
2023-05-29 23:30 ` Jeff Law
2023-05-31 12:19 ` Manolis Tsamis
2023-05-31 14:00 ` Jeff Law
2023-05-25 14:13 ` Jeff Law
2023-05-25 14:18 ` Philipp Tomsich
2023-06-08 5:37 ` Jeff Law
2023-06-12 7:36 ` Manolis Tsamis
2023-06-12 14:37 ` Jeff Law
2023-06-09 0:57 ` Jeff Law
2023-06-12 7:32 ` Manolis Tsamis
2023-06-12 21:58 ` Jeff Law
2023-06-15 17:34 ` Manolis Tsamis
2023-06-10 15:49 ` Jeff Law
2023-06-12 7:41 ` Manolis Tsamis
2023-06-12 21:36 ` Jeff Law
2023-05-25 12:35 ` [PATCH 2/2] cprop_hardreg: Enable propagation of the stack pointer if possible Manolis Tsamis
2023-05-25 13:38 ` Jeff Law
2023-05-31 12:15 ` Manolis Tsamis
2023-06-07 22:16 ` Jeff Law
2023-06-07 22:18 ` Jeff Law
2023-06-08 6:15 ` Manolis Tsamis
2023-06-15 20:13 ` Philipp Tomsich
2023-06-19 16:57 ` Thiago Jung Bauermann
2023-06-19 17:07 ` Manolis Tsamis
2023-06-19 23:40 ` Andrew Pinski
2023-06-19 23:48 ` Andrew Pinski
2023-06-20 2:16 ` Jeff Law
2023-06-20 4:52 ` Tamar Christina [this message]
2023-06-20 5:00 ` Jeff Law
2023-06-21 23:42 ` Thiago Jung Bauermann
2023-06-22 7:37 ` Richard Biener
2023-06-22 7:58 ` Philipp Tomsich
2023-05-25 13:42 ` [PATCH 0/2] RISC-V: New pass to optimize calculation of offsets for memory operations Jeff Law
2023-05-25 13:57 ` Manolis Tsamis
2023-06-15 15:04 ` Jeff Law
2023-06-15 15:30 ` Manolis Tsamis
2023-06-15 15:56 ` Jeff Law
2023-06-18 18:11 ` Jeff Law
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=VI1PR08MB532590CC08F3A7107338799EFF5CA@VI1PR08MB5325.eurprd08.prod.outlook.com \
--to=tamar.christina@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jeffreyalaw@gmail.com \
--cc=kito.cheng@gmail.com \
--cc=manolis.tsamis@vrull.eu \
--cc=palmer@rivosinc.com \
--cc=philipp.tomsich@vrull.eu \
--cc=pinskia@gmail.com \
--cc=richard.guenther@gmail.com \
--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).