* [PATCH] aarch64: Fix eh_return for -mtrack-speculation [PR112987]
@ 2024-01-17 14:37 Szabolcs Nagy
2024-01-24 17:41 ` Richard Sandiford
0 siblings, 1 reply; 2+ messages in thread
From: Szabolcs Nagy @ 2024-01-17 14:37 UTC (permalink / raw)
To: gcc-patches
Recent commit introduced a conditional branch in eh_return epilogues
that is not compatible with speculation tracking:
commit 426fddcbdad6746fe70e031f707fb07f55dfb405
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
CommitDate: 2023-11-27 15:52:48 +0000
aarch64: Use br instead of ret for eh_return
gcc/ChangeLog:
PR target/112987
* config/aarch64/aarch64.cc (aarch64_expand_epilogue): Use
explicit compare and separate jump with speculation tracking.
---
gcc/config/aarch64/aarch64.cc | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index e6bd3fd0bb4..e6de62dc02a 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -9879,7 +9879,17 @@ aarch64_expand_epilogue (rtx_call_insn *sibcall)
is just as correct as retaining the CFA from the body
of the function. Therefore, do nothing special. */
rtx label = gen_label_rtx ();
- rtx x = gen_rtx_EQ (VOIDmode, EH_RETURN_TAKEN_RTX, const0_rtx);
+ rtx x;
+ if (aarch64_track_speculation)
+ {
+ /* Emit an explicit compare, so cc can be tracked. */
+ rtx cc_reg = aarch64_gen_compare_reg (EQ,
+ EH_RETURN_TAKEN_RTX,
+ const0_rtx);
+ x = gen_rtx_EQ (GET_MODE (cc_reg), cc_reg, const0_rtx);
+ }
+ else
+ x = gen_rtx_EQ (VOIDmode, EH_RETURN_TAKEN_RTX, const0_rtx);
x = gen_rtx_IF_THEN_ELSE (VOIDmode, x,
gen_rtx_LABEL_REF (Pmode, label), pc_rtx);
rtx jump = emit_jump_insn (gen_rtx_SET (pc_rtx, x));
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] aarch64: Fix eh_return for -mtrack-speculation [PR112987]
2024-01-17 14:37 [PATCH] aarch64: Fix eh_return for -mtrack-speculation [PR112987] Szabolcs Nagy
@ 2024-01-24 17:41 ` Richard Sandiford
0 siblings, 0 replies; 2+ messages in thread
From: Richard Sandiford @ 2024-01-24 17:41 UTC (permalink / raw)
To: Szabolcs Nagy; +Cc: gcc-patches
Szabolcs Nagy <szabolcs.nagy@arm.com> writes:
> Recent commit introduced a conditional branch in eh_return epilogues
> that is not compatible with speculation tracking:
>
> commit 426fddcbdad6746fe70e031f707fb07f55dfb405
> Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
> CommitDate: 2023-11-27 15:52:48 +0000
>
> aarch64: Use br instead of ret for eh_return
>
> gcc/ChangeLog:
>
> PR target/112987
> * config/aarch64/aarch64.cc (aarch64_expand_epilogue): Use
> explicit compare and separate jump with speculation tracking.
> ---
> gcc/config/aarch64/aarch64.cc | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
> index e6bd3fd0bb4..e6de62dc02a 100644
> --- a/gcc/config/aarch64/aarch64.cc
> +++ b/gcc/config/aarch64/aarch64.cc
> @@ -9879,7 +9879,17 @@ aarch64_expand_epilogue (rtx_call_insn *sibcall)
> is just as correct as retaining the CFA from the body
> of the function. Therefore, do nothing special. */
> rtx label = gen_label_rtx ();
> - rtx x = gen_rtx_EQ (VOIDmode, EH_RETURN_TAKEN_RTX, const0_rtx);
> + rtx x;
> + if (aarch64_track_speculation)
> + {
> + /* Emit an explicit compare, so cc can be tracked. */
> + rtx cc_reg = aarch64_gen_compare_reg (EQ,
> + EH_RETURN_TAKEN_RTX,
> + const0_rtx);
> + x = gen_rtx_EQ (GET_MODE (cc_reg), cc_reg, const0_rtx);
> + }
> + else
> + x = gen_rtx_EQ (VOIDmode, EH_RETURN_TAKEN_RTX, const0_rtx);
It looks from a quick scan like we already have 3 instances of
this kind of construct. Would you mind factoring them out into
a helper?
E.g. (strawman):
static rtx
aarch64_gen_compare_zero_and_branch (rtx_code code, rtx x, rtx_label *label)
{
}
that returns the SET pattern. The caller can then emit the pattern
using whichever interface is appropriate.
Thanks,
Richard
> x = gen_rtx_IF_THEN_ELSE (VOIDmode, x,
> gen_rtx_LABEL_REF (Pmode, label), pc_rtx);
> rtx jump = emit_jump_insn (gen_rtx_SET (pc_rtx, x));
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-24 17:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-17 14:37 [PATCH] aarch64: Fix eh_return for -mtrack-speculation [PR112987] Szabolcs Nagy
2024-01-24 17:41 ` Richard Sandiford
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).