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 expansion of BLKmode MEM_REF with non-addressable non-BLKmode base decl (PR middle-end/51895)


Hi!

Now that Richi has fixed up SRA not to pessimize code by changing non-BLK
mode arguments into their BLKmode subparts, I think it would be nice
to fix up also the expansion of the BLKmode MEM_REFs that have non-BLKmode
non-addressable base decl.  While this doesn't happen for this testcase
anymore, it rarely still occurs and I think it is wrong to expand
a BLKmode MEM_REF into a non-BLKmode rtx.  While the callers sometimes
can cope with it, often they can't.

Bootstrapped/regtested on x86_64-linux and i686-linux, bootstrapped on
powerpc64-linux (both --with-cpu=default32 and with real 64-bit
profiledbootstrap).  Ok for trunk?

2012-01-19  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/51895
	* expr.c (expand_expr_real_1): Handle BLKmode MEM_REF of
	non-addressable non-BLKmode base correctly.

	* g++.dg/opt/pr51895.C: New test.

--- gcc/expr.c.jj	2012-01-13 21:47:35.000000000 +0100
+++ gcc/expr.c	2012-01-19 13:12:14.218760812 +0100
@@ -9328,6 +9328,16 @@ expand_expr_real_1 (tree exp, rtx target
 		bftype = TREE_TYPE (base);
 		if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
 		  bftype = TREE_TYPE (exp);
+		else
+		  {
+		    temp = assign_stack_temp (DECL_MODE (base),
+					      GET_MODE_SIZE (DECL_MODE (base)),
+					      0);
+		    store_expr (base, temp, 0, false);
+		    temp = adjust_address (temp, BLKmode, offset);
+		    set_mem_size (temp, int_size_in_bytes (TREE_TYPE (exp)));
+		    return temp;
+		  }
 		return expand_expr (build3 (BIT_FIELD_REF, bftype,
 					    base,
 					    TYPE_SIZE (TREE_TYPE (exp)),
--- gcc/testsuite/g++.dg/opt/pr51895.C.jj	2012-01-19 13:20:27.808899825 +0100
+++ gcc/testsuite/g++.dg/opt/pr51895.C	2012-01-19 13:21:10.042655293 +0100
@@ -0,0 +1,25 @@
+// PR middle-end/51895
+// { dg-do compile }
+// { dg-options "-O2" }
+
+struct S
+{
+  long a;
+  char b;
+  S () : a (0), b (0) {}
+  bool baz ();
+};
+
+__attribute__((noinline)) static bool
+bar (S x, S y)
+{
+  y = x;
+  return y.baz ();
+}
+
+bool
+foo (S x)
+{
+  S y;
+  return bar (x, y);
+}

	Jakub


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