aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-05-06 09:31:19 +0200
committerJakub Jelinek <jakub@redhat.com>2020-05-06 09:31:19 +0200
commitf14848aea70066777faf201c0b6eb3c5520bfab9 (patch)
tree40a788d722939d41065beb0c1b63add3e11e28e6 /gcc
parent366386c7a970bf6a32c5a2abb714ca6c7f4e7790 (diff)
downloadgcc-f14848aea70066777faf201c0b6eb3c5520bfab9.zip
gcc-f14848aea70066777faf201c0b6eb3c5520bfab9.tar.gz
gcc-f14848aea70066777faf201c0b6eb3c5520bfab9.tar.bz2
combine: Don't replace SET_SRC with REG_EQUAL note content if SET_SRC has side-effects [PR94873]
There were some discussions about whether REG_EQUAL notes are valid on insns with a single set which contains auto-inc-dec side-effects in the SET_SRC and the majority thinks that it should be valid. So, this patch fixes the combiner to punt in that case, because otherwise the auto-inc-dec side-effects from the SET_SRC are lost. 2020-05-06 Jakub Jelinek <jakub@redhat.com> PR rtl-optimization/94873 * combine.c (combine_instructions): Don't optimize using REG_EQUAL note if SET_SRC (set) has side-effects. * gcc.dg/pr94873.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/combine.c1
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/pr94873.c27
4 files changed, 39 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 94f3c25..8040d0d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2020-05-06 Jakub Jelinek <jakub@redhat.com>
+
+ PR rtl-optimization/94873
+ * combine.c (combine_instructions): Don't optimize using REG_EQUAL
+ note if SET_SRC (set) has side-effects.
+
2020-05-06 Hongtao Liu <hongtao.liu@intel.com>
Wei Xiao <wei3.xiao@intel.com>
diff --git a/gcc/combine.c b/gcc/combine.c
index 4c324f3..f69413a 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -1485,6 +1485,7 @@ combine_instructions (rtx_insn *f, unsigned int nregs)
if ((set = single_set (temp)) != 0
&& (note = find_reg_equal_equiv_note (temp)) != 0
&& (note = XEXP (note, 0), GET_CODE (note)) != EXPR_LIST
+ && ! side_effects_p (SET_SRC (set))
/* Avoid using a register that may already been marked
dead by an earlier instruction. */
&& ! unmentioned_reg_p (note, SET_SRC (set))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f8e9f2d..1f01ff0 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-05-06 Jakub Jelinek <jakub@redhat.com>
+
+ PR rtl-optimization/94873
+ * gcc.dg/pr94873.c: New test.
+
2020-05-06 Hongtao.liu <hongtao.liu@intel.com>
Wei Xiao <wei3.xiao@intel.com>
diff --git a/gcc/testsuite/gcc.dg/pr94873.c b/gcc/testsuite/gcc.dg/pr94873.c
new file mode 100644
index 0000000..3615217
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr94873.c
@@ -0,0 +1,27 @@
+/* PR rtl-optimization/94873 */
+/* { dg-do run { target int128 } } */
+/* { dg-options "-O -fno-merge-constants -fno-split-wide-types -fno-tree-fre" } */
+
+__attribute__((noipa)) void
+foo (const char *p, int q)
+{
+ if (p[0] != '%' || p[1] != '0' || p[2] != '2' || p[3] != 'x' || p[4] != '\0')
+ __builtin_abort ();
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+ if ((unsigned char) q != 0x95)
+ __builtin_abort ();
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ if ((unsigned char) q != 0)
+ __builtin_abort ();
+#endif
+}
+
+int
+main ()
+{
+ union U { __int128 a; char b[sizeof (__int128)]; };
+ char x = ((union U){ .a = 0xF4409395252B9560ULL}).b[1];
+ for (unsigned i = 0; i < sizeof (x); i++)
+ foo ("%02x", i[(volatile unsigned char *) &x]);
+ return 0;
+}