]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: Prevent moving throwing accesses in ldp/stp pass [PR113093]
authorAlex Coplan <alex.coplan@arm.com>
Thu, 21 Dec 2023 10:52:44 +0000 (10:52 +0000)
committerAlex Coplan <alex.coplan@arm.com>
Thu, 21 Dec 2023 10:52:44 +0000 (10:52 +0000)
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.

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.

gcc/config/aarch64/aarch64-ldp-fusion.cc
gcc/testsuite/gcc.dg/pr113093.c [new file with mode: 0644]

index 0e2c299a0bfa42d3fa3b05be98eb18a3b4d17cd6..59db70e9cd0d8c1ef8e18669f10a067a8a522458 100644 (file)
@@ -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 (file)
index 0000000..af2a334
--- /dev/null
@@ -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; }