Patch to improve PIC find_base_term (version 2)

John Wehle john@feith.com
Wed Aug 23 12:12:00 GMT 2000


This patch allows alias analysis to understand PIC addresses.
This patch passes make bootstrap and make check on FreeBSD-3.5 x86.

ChangeLog:

Wed Aug 23 13:27:52 EDT 2000  John Wehle  (john@feith.com)

	* i386.c (ix86_find_base_term): New.
	* i386-protos.h (ix86_find_base_term): Prototype.
	* i386.h (FIND_BASE_TERM): Define.
	* alias.c (find_base_term): Use it.
	* tm.texi (FIND_BASE_TERM): Document it.

Enjoy!

-- John Wehle
------------------8<------------------------8<------------------------
*** gcc/config/i386/i386.c.ORIGINAL	Tue Aug 22 23:49:25 2000
--- gcc/config/i386/i386.c	Wed Aug 23 03:12:44 2000
*************** ix86_address_cost (x)
*** 2332,2337 ****
--- 2332,2371 ----
    return cost;
  }
  
+ /* If X is a machine specific address (i.e. a symbol or label being
+    referenced as a displacement from the GOT implemented using an
+    UNSPEC), then return the base term.  Otherwise return X.  */
+ 
+ rtx
+ ix86_find_base_term (x)
+      rtx x;
+ {
+   rtx term;
+ 
+   if (GET_CODE (x) != PLUS
+       || XEXP (x, 0) != pic_offset_table_rtx
+       || GET_CODE (XEXP (x, 1)) != CONST)
+     return x;
+ 
+   term = XEXP (XEXP (x, 1), 0);
+ 
+   if (GET_CODE (term) == PLUS && GET_CODE (XEXP (term, 1)) == CONST_INT)
+     term = XEXP (term, 0);
+ 
+   if (GET_CODE (term) != UNSPEC
+       || XVECLEN (term, 0) != 1
+       || XINT (term, 1) !=  7)
+     return x;
+ 
+   term = XVECEXP (term, 0, 0);
+ 
+   if (GET_CODE (term) != SYMBOL_REF
+       && GET_CODE (term) != LABEL_REF)
+     return x;
+ 
+   return term;
+ }
+ 
  /* Determine if a given CONST RTX is a valid memory displacement
     in PIC mode.  */
     
*** gcc/config/i386/i386-protos.h.ORIGINAL	Sat Jul  8 21:22:44 2000
--- gcc/config/i386/i386-protos.h	Wed Aug 23 03:10:14 2000
*************** extern void ix86_split_ashrdi PARAMS ((r
*** 111,116 ****
--- 111,117 ----
  extern void ix86_split_lshrdi PARAMS ((rtx *, rtx));
  extern void ix86_expand_strlensi_unroll_1 PARAMS ((rtx, rtx, rtx));
  extern int ix86_address_cost PARAMS ((rtx));
+ extern rtx ix86_find_base_term PARAMS ((rtx));
  
  extern rtx assign_386_stack_local PARAMS ((enum machine_mode, int));
  extern int ix86_attr_length_immediate_default PARAMS ((rtx, int));
*** gcc/config/i386/i386.h.ORIGINAL	Thu Aug 17 13:18:10 2000
--- gcc/config/i386/i386.h	Wed Aug 23 03:09:22 2000
*************** pop{l} %0"							\
*** 1659,1664 ****
--- 1659,1675 ----
  
  #endif
  
+ /* If defined, a C expression to determine the base term of address X.
+    This macro is used in only one place: `find_base_term' in alias.c.
+ 
+    It is always safe for this macro to not be defined.  It exists so
+    that alias analysis can understand machine-dependent addresses.
+ 
+    The typical use of this macro is to handle addresses containing
+    a label_ref or symbol_ref within an UNSPEC.  */
+ 
+ #define FIND_BASE_TERM(X) ix86_find_base_term (x)
+ 
  /* Try machine-dependent ways of modifying an illegitimate address
     to be legitimate.  If we find one, return the new, valid address.
     This macro is used in only one place: `memory_address' in explow.c.
*** gcc/alias.c.ORIGINAL	Tue Aug 22 23:49:05 2000
--- gcc/alias.c	Wed Aug 23 03:09:03 2000
*************** find_base_term (x)
*** 1033,1038 ****
--- 1033,1043 ----
    cselib_val *val;
    struct elt_loc_list *l;
  
+ #if defined (FIND_BASE_TERM)
+   /* Try machine-dependent ways to find the base term.  */
+   x = FIND_BASE_TERM (x);
+ #endif
+ 
    switch (GET_CODE (x))
      {
      case REG:
*************** find_base_term (x)
*** 1078,1083 ****
--- 1083,1091 ----
  	   is a shift or multiply, then it must be the index register and the
  	   other operand is the base register.  */
  	
+ 	if (tmp1 == pic_offset_table_rtx && CONSTANT_P (tmp2))
+ 	  return find_base_term (tmp2);
+ 
  	/* If either operand is known to be a pointer, then use it
  	   to determine the base term.  */
  	if (REG_P (tmp1) && REGNO_POINTER_FLAG (REGNO (tmp1)))
*** gcc/tm.texi.ORIGINAL	Thu Aug 17 13:17:48 2000
--- gcc/tm.texi	Wed Aug 23 13:26:55 2000
*************** may serve in each capacity.  The compile
*** 4453,4458 ****
--- 4453,4469 ----
  looking for one that is valid, and will reload one or both registers
  only if neither labeling works.
  
+ @findex FIND_BASE_TERM
+ @item FIND_BASE_TERM (@var{x})
+ A C expression to determine the base term of address @var{x}.
+ This macro is used in only one place: `find_base_term' in alias.c.
+ 
+ It is always safe for this macro to not be defined.  It exists so
+ that alias analysis can understand machine-dependent addresses.
+ 
+ The typical use of this macro is to handle addresses containing
+ a label_ref or symbol_ref within an UNSPEC.
+ 
  @findex LEGITIMIZE_ADDRESS
  @item LEGITIMIZE_ADDRESS (@var{x}, @var{oldx}, @var{mode}, @var{win})
  A C compound statement that attempts to replace @var{x} with a valid
-------------------------------------------------------------------------
|   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john@feith.com  |
|    John Wehle    |     Fax: 1-215-540-5495  |                         |
-------------------------------------------------------------------------



More information about the Gcc-patches mailing list