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 PR optimization/7675


Hi,

This is a regression from gcc 2.95.3 present in all 3.x versions. The compiler 
ICEs when fixing the insns of a parent function after its child caused some 
registers to be put into the stack, because the recognizer chokes on:

(insn 14 11 0 (set (mem/f:SI (plus:SI (reg/f:SI 54 virtual-stack-vars)
                (const_int -4 [0xfffffffc])) [0 S4 A8])
        (mem/f:SI (addressof:SI (mem/f:SI (plus:SI (reg/f:SI 54 
virtual-stack-vars)
                        (const_int -8 [0xfffffff8])) [0 S4 A8]) 58 0x4016b690) 
[0 i+0 S4 A32])) -1 (nil)
    (nil))

when trying to fix the (ADDRESSOF (MEM ...))) pattern.

The problem is that, since fixing for the parent function is deferred until 
after the RTL code has been emitted for its child, the two regs in the 
following insn are replaced in a row:

(insn 14 11 0 (set (reg:SI ...))
        (mem/f:SI (addressof:SI (reg:SI ...) 58 0x4016b690) [0 i+0 S4 A32])) 
-1 (nil)
    (nil))

I guess the true fix would be to somehow undo the reg-to-stack transformations 
at the end of the child function and replay them one by one. But that seems 
like overkill, so the proposed fix is to simplify the (MEM (ADDRESSOF (MEM))) 
pattern instead. Bootstrapped/regtested on i586-redhat-linux-gnu 
(c,c++,objc,f77 mainline).

-- 
Eric Botcazou


2002-12-05  Eric Botcazou  <ebotcazou@libertysurf.fr>

	PR optimization/7675
	* function.c (fixup_var_refs_1) [MEM]: Simplify the
	(MEM (ADDRESSOF (MEM ...))) pattern.

2002-12-05  Eric Botcazou  <ebotcazou@libertysurf.fr>

	* gcc.c-torture/compile/20021205-1.c: New test.


Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.388
diff -u -r1.388 function.c
--- function.c	27 Nov 2002 02:29:12 -0000	1.388
+++ function.c	5 Dec 2002 16:00:27 -0000
@@ -2006,7 +2006,33 @@
 	{
 	  replacement = find_fixup_replacement (replacements, x);
 	  if (replacement->new == 0)
-	    replacement->new = copy_most_rtx (x, no_share);
+	    {
+	      rtx arg = XEXP (x, 0);
+
+	      replacement->new = copy_most_rtx (x, no_share);
+
+	      /* Simplify (MEM (ADDRESSOF (MEM ...))) here because it may have
+	   	 been generated by put_reg_into_stack from within a nested
+	   	 function when turning
+
+		   (SET (REG) (MEM (ADDRESSOF (REG))))
+
+		 into
+
+		   (SET (MEM) (MEM (ADDRESSOF (MEM)))) .
+
+		 The problem is that *both* REGs are put into the stack in a
+		 row so we would need to apply the ADDRESSOF fix and the SET
+		 fix simultaneously.  */
+
+	      if (GET_CODE (arg) == ADDRESSOF && XEXP (arg, 0) == var)
+		{
+		  XEXP (replacement->new, 0)
+		    = XEXP (XEXP (XEXP (replacement->new, 0), 0), 0);
+		  *loc = replacement->new;
+		  return;
+		}
+	    }
 
 	  *loc = x = replacement->new;
 	  code = GET_CODE (x);


/* PR optimization/7675 */
/* Contributed by Volker Reichelt */

extern void dummy (int *);

void foo(int i)
{
  int j=i;

  void bar() { int x=j, y=i; }

  dummy(&i);
}


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