]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
avoid-store-forwarding: bail when an instruction may throw [PR117816]
authorkelefth <konstantinos.eleftheriou@vrull.eu>
Thu, 5 Dec 2024 10:11:27 +0000 (11:11 +0100)
committerPhilipp Tomsich <philipp.tomsich@vrull.eu>
Fri, 6 Dec 2024 11:36:42 +0000 (12:36 +0100)
Avoid-store-forwarding doesn't handle the case where an instruction in
the store-load sequence contains a REG_EH_REGION note, leading to the
insertion of instructions after it, while it should be the last
instruction in the basic block. This causes an ICE when compiling
using `-O -fnon-call-exceptions -favoid-store-forwarding
-fno-forward-propagate -finstrument-functions`.

This patch rejects the transformation when there are instructions in
the sequence that may throw an exeption.

PR rtl-optimization/117816

gcc/ChangeLog:

* avoid-store-forwarding.cc (store_forwarding_analyzer::avoid_store_forwarding):
Reject the transformation when having instructions that may
throw exceptions in the sequence.

gcc/testsuite/ChangeLog:

* gcc.dg/pr117816.c: New test.

gcc/avoid-store-forwarding.cc
gcc/testsuite/gcc.dg/pr117816.c [new file with mode: 0644]

index b1fa1678dc30a3db75e4400cfee0a3391ddc18d7..1b8c35bc6cb7b497a364a38c69b9fdb34bc16f2e 100644 (file)
@@ -429,7 +429,7 @@ store_forwarding_analyzer::avoid_store_forwarding (basic_block bb)
 
       rtx set = single_set (insn);
 
-      if (!set)
+      if (!set || insn_could_throw_p (insn))
        {
          store_exprs.truncate (0);
          continue;
diff --git a/gcc/testsuite/gcc.dg/pr117816.c b/gcc/testsuite/gcc.dg/pr117816.c
new file mode 100644 (file)
index 0000000..6a9fc5f
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fnon-call-exceptions -favoid-store-forwarding -fno-forward-propagate -finstrument-functions" } */
+
+char *p;
+int y;
+long x;
+
+void foo()
+{
+  x /= *(int *)__builtin_memmove(&y, 4 + p, 3);
+}