This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix crossjumping (PR rtl-optimization/58365)


Hi!

If two instructions are rtl_equal_p, and cross-jumping decides to cross-jump
them together, merge_memattrs takes care of clearing various MEM_ATTRS
or setting alignment to minimum, size to maximum etc.
But, it didn't handle flags on the MEMs.

The following patch fixes that.  MEM_KEEP_ALIAS_SET_P from quick skimming
seems to be used only during expansion and thus can be ignored IMHO.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.8?

BTW, I wonder about REG_ATTRS and REG_POINTER, REG_USERVAR_P,
REG_FUNCTION_VALUE_P, is it fine to keep them as is (as in, can rtx_equal_p
for REG only compares REGNO and mode, nothing else, not sure if we could
end up with differences in any of those during cross-jumping and whether
it could affect code generation).

2013-09-10  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/58365
	* cfgcleanup.c (merge_memattrs): Also clear MEM_READONLY_P
	resp. MEM_NOTRAP_P if they differ, or set MEM_VOLATILE_P if
	it differs.

	* gcc.c-torture/execute/pr58365.c: New test.

--- gcc/cfgcleanup.c.jj	2013-09-09 11:32:42.000000000 +0200
+++ gcc/cfgcleanup.c	2013-09-10 09:13:43.783165931 +0200
@@ -925,6 +925,24 @@ merge_memattrs (rtx x, rtx y)
 	  set_mem_align (y, MEM_ALIGN (x));
 	}
     }
+  if (code == MEM)
+    {
+      if (MEM_READONLY_P (x) != MEM_READONLY_P (y))
+	{
+	  MEM_READONLY_P (x) = 0;
+	  MEM_READONLY_P (y) = 0;
+	}
+      if (MEM_NOTRAP_P (x) != MEM_NOTRAP_P (y))
+	{
+	  MEM_NOTRAP_P (x) = 0;
+	  MEM_NOTRAP_P (y) = 0;
+	}
+      if (MEM_VOLATILE_P (x) != MEM_VOLATILE_P (y))
+	{
+	  MEM_VOLATILE_P (x) = 1;
+	  MEM_VOLATILE_P (y) = 1;
+	}
+    }
 
   fmt = GET_RTX_FORMAT (code);
   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
--- gcc/testsuite/gcc.c-torture/execute/pr58365.c.jj	2013-09-10 09:20:01.761164460 +0200
+++ gcc/testsuite/gcc.c-torture/execute/pr58365.c	2013-09-10 09:19:18.000000000 +0200
@@ -0,0 +1,35 @@
+/* PR rtl-optimization/58365 */
+
+extern void abort (void);
+
+struct S
+{
+  volatile int a;
+  int b, c, d, e;
+} f;
+static struct S g, h;
+int i = 1;
+
+char
+foo (void)
+{
+  return i;
+}
+
+static struct S
+bar (void)
+{
+  if (foo ())
+    return f;
+  return g;
+}
+
+int
+main ()
+{
+  h = bar ();
+  f.b = 1;
+  if (h.b != 0)
+    abort ();
+  return 0;
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]