diff mbox series

aarch64: Prevent moving throwing accesses in ldp/stp pass [PR113093]

Message ID ZYNrdL2poDoga934@arm.com
State New
Headers show
Series aarch64: Prevent moving throwing accesses in ldp/stp pass [PR113093] | expand

Commit Message

Alex Coplan Dec. 20, 2023, 10:32 p.m. UTC
As the PR shows, there was nothing to prevent the ldp/stp pass from
trying to move throwing insns, which lead to an RTL verification
failure.

This patch fixes that.

Bootstrapped/regtested on aarch64-linux-gnu, OK for trunk?

Thanks,
Alex

gcc/ChangeLog:

	PR target/113093
	* config/aarch64/aarch64-ldp-fusion.cc (latest_hazard_before):
	If the insn is throwing, record the previous insn as a hazard to
	prevent moving it from the end of the BB.

gcc/testsuite/ChangeLog:

	PR target/113093
	* gcc.dg/pr113093.c: New test.

Comments

Richard Sandiford Dec. 21, 2023, 10:18 a.m. UTC | #1
Alex Coplan <alex.coplan@arm.com> writes:
> As the PR shows, there was nothing to prevent the ldp/stp pass from
> trying to move throwing insns, which lead to an RTL verification
> failure.
>
> This patch fixes that.
>
> Bootstrapped/regtested on aarch64-linux-gnu, OK for trunk?
>
> Thanks,
> Alex
>
> gcc/ChangeLog:
>
> 	PR target/113093
> 	* config/aarch64/aarch64-ldp-fusion.cc (latest_hazard_before):
> 	If the insn is throwing, record the previous insn as a hazard to
> 	prevent moving it from the end of the BB.
>
> gcc/testsuite/ChangeLog:
>
> 	PR target/113093
> 	* gcc.dg/pr113093.c: New test.

OK, thanks.

Richard

> diff --git a/gcc/config/aarch64/aarch64-ldp-fusion.cc b/gcc/config/aarch64/aarch64-ldp-fusion.cc
> index 0e2c299a0bf..59db70e9cd0 100644
> --- a/gcc/config/aarch64/aarch64-ldp-fusion.cc
> +++ b/gcc/config/aarch64/aarch64-ldp-fusion.cc
> @@ -618,6 +618,13 @@ latest_hazard_before (insn_info *insn, rtx *ignore,
>  {
>    insn_info *result = nullptr;
>  
> +  // If the insn can throw then it is at the end of a BB and we can't
> +  // move it, model this by recording a hazard in the previous insn
> +  // which will prevent moving the insn up.
> +  if (cfun->can_throw_non_call_exceptions
> +      && find_reg_note (insn->rtl (), REG_EH_REGION, NULL_RTX))
> +    return insn->prev_nondebug_insn ();
> +
>    // Return true if we registered the hazard.
>    auto hazard = [&](insn_info *h) -> bool
>      {
> diff --git a/gcc/testsuite/gcc.dg/pr113093.c b/gcc/testsuite/gcc.dg/pr113093.c
> new file mode 100644
> index 00000000000..af2a334b45d
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr113093.c
> @@ -0,0 +1,4 @@
> +/* { dg-do compile } */
> +/* { dg-options "-Os -fharden-control-flow-redundancy -fnon-call-exceptions" } */
> +_Complex long *c;
> +void init() { *c = 1.0; }
diff mbox series

Patch

diff --git a/gcc/config/aarch64/aarch64-ldp-fusion.cc b/gcc/config/aarch64/aarch64-ldp-fusion.cc
index 0e2c299a0bf..59db70e9cd0 100644
--- a/gcc/config/aarch64/aarch64-ldp-fusion.cc
+++ b/gcc/config/aarch64/aarch64-ldp-fusion.cc
@@ -618,6 +618,13 @@  latest_hazard_before (insn_info *insn, rtx *ignore,
 {
   insn_info *result = nullptr;
 
+  // If the insn can throw then it is at the end of a BB and we can't
+  // move it, model this by recording a hazard in the previous insn
+  // which will prevent moving the insn up.
+  if (cfun->can_throw_non_call_exceptions
+      && find_reg_note (insn->rtl (), REG_EH_REGION, NULL_RTX))
+    return insn->prev_nondebug_insn ();
+
   // Return true if we registered the hazard.
   auto hazard = [&](insn_info *h) -> bool
     {
diff --git a/gcc/testsuite/gcc.dg/pr113093.c b/gcc/testsuite/gcc.dg/pr113093.c
new file mode 100644
index 00000000000..af2a334b45d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr113093.c
@@ -0,0 +1,4 @@ 
+/* { dg-do compile } */
+/* { dg-options "-Os -fharden-control-flow-redundancy -fnon-call-exceptions" } */
+_Complex long *c;
+void init() { *c = 1.0; }