[gcc r14-9379] fwprop: Avoid volatile rtx to be propagated
HaoChen Gui
guihaoc@gcc.gnu.org
Fri Mar 8 01:32:25 GMT 2024
https://gcc.gnu.org/g:a0e945888d973fc1a4a9d2944aa7e96d2a4d7581
commit r14-9379-ga0e945888d973fc1a4a9d2944aa7e96d2a4d7581
Author: Haochen Gui <guihaoc@gcc.gnu.org>
Date: Fri Mar 8 09:30:35 2024 +0800
fwprop: Avoid volatile rtx to be propagated
The patch for PR111267 (commit id 86de9b66480b710202a2898cf513db105d8c432f)
which introduces an exception for propagation on single set insn. The
propagation which might not be profitable (checked by profitable_p) is still
allowed to be propagated to single set insn. It has a potential problem
that a volatile operand might be propagated to a singel set insn. If the
define insn is not eliminated after propagation, the volatile operand will
be executed for multiple times. This patch fixes the problem by skipping
volatile set source rtx in propagation.
gcc/
* fwprop.cc (forward_propagate_into): Return false for volatile set
source rtx.
gcc/testsuite/
* gcc.target/powerpc/fwprop-1.c: New.
Diff:
---
gcc/fwprop.cc | 2 ++
gcc/testsuite/gcc.target/powerpc/fwprop-1.c | 15 +++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/gcc/fwprop.cc b/gcc/fwprop.cc
index 7872609b336..cb6fd6700ca 100644
--- a/gcc/fwprop.cc
+++ b/gcc/fwprop.cc
@@ -854,6 +854,8 @@ forward_propagate_into (use_info *use, bool reg_prop_only = false)
rtx dest = SET_DEST (def_set);
rtx src = SET_SRC (def_set);
+ if (volatile_refs_p (src))
+ return false;
/* Allow propagations into a loop only for reg-to-reg copies, since
replacing one register by another shouldn't increase the cost.
diff --git a/gcc/testsuite/gcc.target/powerpc/fwprop-1.c b/gcc/testsuite/gcc.target/powerpc/fwprop-1.c
new file mode 100644
index 00000000000..07b207f980c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/fwprop-1.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-rtl-fwprop1-details" } */
+/* { dg-final { scan-rtl-dump-not "propagating insn" "fwprop1" } } */
+
+/* Verify that volatile asm operands doesn't try to be propagated. */
+long long foo ()
+{
+ long long res;
+ __asm__ __volatile__(
+ ""
+ : "=r" (res)
+ :
+ : "memory");
+ return res;
+}
More information about the Gcc-cvs
mailing list