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]

Complex types aliasing and MEM_IN_STRUCT_P


This patch fixes an RTL aliasing bug with complex types.  The included
testcase triggers the problem for arm-none-linux-gnueabi on 4.1 branch
but not on 4.2 or trunk, but I believe the problem is still present on
trunk although I don't have a test showing it there.

fixed_scalar_and_varying_struct_p decides that the stores to parts of
*fp_cxd(&cx) are stores to a variable-address struct, while loads of
__real__(cx) and __imag__(cx) are loads of constant address scalars,
and therefore that they cannot conflict and so the loads can be moved
before the stores, although the stores in fact are storing to cx.

When a component is extracted from a type that access may be marked as a
struct access.  This means MEMs for types from which components get
extracted must not be marked as scalar MEMs - and this includes
complex types as well as aggregates.  This patch changes two places to
handle complex types the same as aggregates in this regard.

Bootstrapped with no regressions on i686-pc-linux-gnu.  OK to commit?

2007-02-14  Joseph Myers  <joseph@codesourcery.com>

	* emit-rtl.c (set_mem_attributes_minus_bitpos): Treat complex
	types as aggregates not scalars.
	* function.c (assign_stack_temp_for_type): Likewise.

testsuite:
2007-02-14  Joseph Myers  <joseph@codesourcery.com>

	* gcc.dg/torture/complex-alias-1.c: New test.

Index: emit-rtl.c
===================================================================
--- emit-rtl.c	(revision 121893)
+++ emit-rtl.c	(working copy)
@@ -1481,12 +1481,15 @@
   alias = get_alias_set (t);
 
   MEM_VOLATILE_P (ref) |= TYPE_VOLATILE (type);
-  MEM_IN_STRUCT_P (ref) = AGGREGATE_TYPE_P (type);
+  MEM_IN_STRUCT_P (ref)
+    = AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE;
   MEM_POINTER (ref) = POINTER_TYPE_P (type);
 
   /* If we are making an object of this type, or if this is a DECL, we know
      that it is a scalar if the type is not an aggregate.  */
-  if ((objectp || DECL_P (t)) && ! AGGREGATE_TYPE_P (type))
+  if ((objectp || DECL_P (t))
+      && ! AGGREGATE_TYPE_P (type)
+      && TREE_CODE (type) != COMPLEX_TYPE)
     MEM_SCALAR_P (ref) = 1;
 
   /* We can set the alignment from the type if we are making an object,
Index: function.c
===================================================================
--- function.c	(revision 121893)
+++ function.c	(working copy)
@@ -763,7 +763,8 @@
   if (type != 0)
     {
       MEM_VOLATILE_P (slot) = TYPE_VOLATILE (type);
-      MEM_SET_IN_STRUCT_P (slot, AGGREGATE_TYPE_P (type));
+      MEM_SET_IN_STRUCT_P (slot, (AGGREGATE_TYPE_P (type)
+				  || TREE_CODE (type) == COMPLEX_TYPE));
     }
   MEM_NOTRAP_P (slot) = 1;
 
Index: testsuite/gcc.dg/torture/complex-alias-1.c
===================================================================
--- testsuite/gcc.dg/torture/complex-alias-1.c	(revision 0)
+++ testsuite/gcc.dg/torture/complex-alias-1.c	(revision 0)
@@ -0,0 +1,29 @@
+/* Accesses to complex numbers were sometimes marked as scalar and
+   sometimes as struct accesses.  */
+/* { dg-do run } */
+/* { dg-options "-std=c99" } */
+
+extern void abort (void);
+static double _Complex *fp_cxd(double _Complex *cx) {
+  return cx;
+}
+
+int main( ) {
+  double _Complex cx = 4.0 + 3.0*(__extension__ 1.0iF);
+  double _Complex cx43 = 4.0 + 3.0*(__extension__ 1.0iF);
+  double _Complex cx11 = 1.0 + 1.0*(__extension__ 1.0iF);
+
+  *fp_cxd(&cx) *= cx11;
+  *fp_cxd(&cx) /= cx11;
+
+  double r_cx = __real__(cx);
+  double i_cx = __imag__(cx);
+  double r_cx43 = __real__(cx43);
+  double i_cx43 = __imag__(cx43);
+
+  if( (r_cx == r_cx43) && (i_cx == i_cx43) ) { 
+    return 0;
+  } else {
+    abort ();
+  }
+}

-- 
Joseph S. Myers
joseph@codesourcery.com


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