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][rfc] PR20928


Hi,

This is my proposed fix for PR20928.

The old loop optimizer tries to hoist some address arithmetic in the
test case for this bug.  But the invariant insn is not actually moved.
It is just rebuilt instead, and the problem is that it is not rebuilt
correctly.  In the loop, the invariant insns look something like this:

(set (reg:DI 66) (mem:DI (const:DI (unspec:DI [(symbol_ref:DI ("bar"))])))) 
(set (reg:DI 68) (const_int 2147483648 [0x80000000])) 
(parallel [ 
  (set (reg:DI 67) (plus:DI (reg:DI 66) (reg:DI 68))) 
  (clobber (reg:CC 17 flags))]) 

Note that the const_int is loaded into a register.  IIUC this happens
because it is not a valid PIC offset.  But after loop.c emits the new
insns, we get this:

(set (reg:DI 69) (mem:DI (const:DI (unspec:DI [(symbol_ref:DI ("bar"))])))) 
(set (reg/f:DI 67) (plus:DI (reg:DI 69) (const_int 2147483648 [0x80000000]))) 

And the second insn is unrecognizable...

I think the problem is that legitimize_pic_address builds a base+offset
address without verifying that the offset is valid.  The patch below
adds a check for that.

I have bootstrapped and tested mainline with the patch on
x86_64-unknown-linux-gnu with c,c++,objc,f95 enabled, but not java
because it fails.  I have a bootstrap&test running for 4.0+patch right
now.

Does this look like the proper fix?  If so, OK for mainline and for 4.0
when it opens again for regression fixes.  I would obviously do a full
test cycle before commiting...

Gr.
Steven


	* config/i386/i386.c (legitimize_pic_address): When building a
	base+offset address, make sure that the offset is legitimate.

Index: config/i386/i386.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.807
diff -u -3 -p -r1.807 i386.c
--- config/i386/i386.c	9 Apr 2005 17:19:48 -0000	1.807
+++ config/i386/i386.c	10 Apr 2005 21:01:26 -0000
@@ -5612,7 +5612,13 @@ legitimize_pic_address (rtx orig, rtx re
 					     base == reg ? NULL_RTX : reg);
 
 	      if (GET_CODE (new) == CONST_INT)
-		new = plus_constant (base, INTVAL (new));
+		{
+		  if (legitimate_pic_address_disp_p (new))
+		    new = plus_constant (base, INTVAL (new));
+		  else
+		    new = gen_rtx_PLUS (Pmode, base,
+					copy_to_mode_reg (Pmode, new));
+		}
 	      else
 		{
 		  if (GET_CODE (new) == PLUS && CONSTANT_P (XEXP (new, 1)))


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