Patchwork Improve MEM_REF expansion (PR target/45670)

login
register
mail settings
Submitter Jakub Jelinek
Date Nov. 5, 2010, 5:41 p.m.
Message ID <20101105174154.GJ29412@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/70272/
State New
Headers show

Comments

Jakub Jelinek - Nov. 5, 2010, 5:41 p.m.
Hi!

Without EXPAND_SUM op0 is often not as complex as some targets (e.g.
i?86/x86_64) can handle in memory addresses and in some cases, as in the
testcase below, if we expand it wrong way we aren't able to fix it up
afterwards.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2010-11-05  Jakub Jelinek  <jakub@redhat.com>

	PR target/45670
	* expr.c (expand_expr_real_1) <case MEM_REF>: Use EXPAND_SUM
	instead of EXPAND_NORMAL for base expansion.

	* gcc.target/i386/pr45670.c: New test.


	Jakub
Richard Henderson - Nov. 5, 2010, 6:19 p.m.
On 11/05/2010 10:41 AM, Jakub Jelinek wrote:
> 	PR target/45670
> 	* expr.c (expand_expr_real_1) <case MEM_REF>: Use EXPAND_SUM
> 	instead of EXPAND_NORMAL for base expansion.
> 
> 	* gcc.target/i386/pr45670.c: New test.

Ok.


r~

Patch

--- gcc/expr.c.jj	2010-11-01 09:07:22.000000000 +0100
+++ gcc/expr.c	2010-11-05 11:19:21.000000000 +0100
@@ -8712,7 +8712,7 @@  expand_expr_real_1 (tree exp, rtx target
 	  }
 	align = MAX (TYPE_ALIGN (TREE_TYPE (exp)),
 		     get_object_alignment (exp, BIGGEST_ALIGNMENT));
-	op0 = expand_expr (base, NULL_RTX, VOIDmode, EXPAND_NORMAL);
+	op0 = expand_expr (base, NULL_RTX, VOIDmode, EXPAND_SUM);
 	op0 = convert_memory_address_addr_space (address_mode, op0, as);
 	if (!integer_zerop (TREE_OPERAND (exp, 1)))
 	  {
--- gcc/testsuite/gcc.target/i386/pr45670.c.jj	2010-11-05 11:42:22.000000000 +0100
+++ gcc/testsuite/gcc.target/i386/pr45670.c	2010-11-05 11:41:28.000000000 +0100
@@ -0,0 +1,23 @@ 
+/* PR target/45670 */
+/* { dg-do compile } */
+/* { dg-options "-Os -mtune=generic" } */
+
+struct S
+{
+  float *buf;
+  int size;
+};
+
+void
+foo (struct S *s)
+{
+  int i;
+  for (i = 0; i < s->size; ++i)
+    s->buf[i] = 0;
+}
+
+/* Ensure we don't generate
+   lea (reg1,4),reg2; add (reg3),reg2; movl $0, (reg2)
+   instead of smaller
+   mov (reg3),reg2; movl $0, (reg2,reg1,4)  */
+/* { dg-final { scan-assembler-not "lea\[lq\]" } } */