Patch for reload bug on ARM chip

Jeffrey A Law law@cygnus.com
Mon Aug 21 06:45:00 GMT 2000


Here's the patch to fix the reload bug I mentioned over the weekend.

Basically I broke out the code to determine when the inner part of a SUBREG
will need reloading from push_reload and use it to avoid combining reloads.

Survived bootstrapping on the x86.

        * reload.c (reload_inner_reg_of_subreg): New function broken out of
        push_reload.
        (push_reload): Use reload_inner_reg_of_subreg.
        (combine_reloads): Do not combine reloads if the input reload
        is a SUBREG in which the inner part will need reloading.

Index: reload.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/reload.c,v
retrieving revision 1.120
diff -c -3 -p -r1.120 reload.c
*** reload.c	2000/08/21 13:42:29	1.120
--- reload.c	2000/08/21 13:43:13
*************** static int push_secondary_reload PARAMS 
*** 243,248 ****
--- 243,249 ----
  					enum insn_code *));
  #endif
  static enum reg_class find_valid_class PARAMS ((enum machine_mode, int));
+ static int reload_inner_reg_of_subreg PARAMS ((rtx, enum machine_mode));
  static int push_reload		PARAMS ((rtx, rtx, rtx *, rtx *, enum reg_class,
  				       enum machine_mode, enum machine_mode,
  				       int, int, int, enum reload_type));
*************** find_reusable_reload (p_in, out, class, 
*** 767,772 ****
--- 768,812 ----
    return n_reloads;
  }
  
+ /* Return nonzero if X is a SUBREG which will require reloading of its
+    SUBREG_REG expression.  */
+ 
+ static int
+ reload_inner_reg_of_subreg (x, mode)
+      rtx x;
+      enum machine_mode mode;
+ {
+   rtx inner;
+ 
+   /* Only SUBREGs are problematical.  */
+   if (GET_CODE (x) != SUBREG)
+     return 0;
+ 
+   inner = SUBREG_REG (x);
+ 
+   /* If INNER is a constant, then INNER must be reloaded.  */
+   if (CONSTANT_P (inner))
+     return 1;
+ 
+   /* If INNER is not a hard register, then INNER will not need to
+      be reloaded.  */
+   if (GET_CODE (inner) != REG
+       || REGNO (inner) >= FIRST_PSEUDO_REGISTER)
+     return 0;
+ 
+   /* If INNER is not ok for MODE, then INNER will need reloading.  */
+   if (! HARD_REGNO_MODE_OK (REGNO (inner) + SUBREG_WORD (x), mode))
+     return 1;
+ 
+   /* If the outer part is a word or smaller, INNER larger than a
+      word and the number of regs for INNER is not the same as the
+      number of words in INNER, then INNER will need reloading.  */
+   return (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
+ 	  && GET_MODE_SIZE (GET_MODE (inner)) > UNITS_PER_WORD
+ 	  && ((GET_MODE_SIZE (GET_MODE (inner)) / UNITS_PER_WORD)
+ 	      != HARD_REGNO_NREGS (REGNO (inner), GET_MODE (inner))));
+ }
+ 
  /* Record one reload that needs to be performed.
     IN is an rtx saying where the data are to be found before this 
instruction.
     OUT says where they must be stored after the instruction.
*************** push_reload (in, out, inloc, outloc, cla
*** 993,1012 ****
    /* Similar issue for (SUBREG constant ...) if it was not handled by the
       code above.  This can happen if SUBREG_WORD != 0.  */
  
!   if (in != 0 && GET_CODE (in) == SUBREG
!       && (CONSTANT_P (SUBREG_REG (in))
! 	  || (GET_CODE (SUBREG_REG (in)) == REG
! 	      && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
! 	      && (! HARD_REGNO_MODE_OK (REGNO (SUBREG_REG (in))
! 					+ SUBREG_WORD (in),
! 					inmode)
! 		  || (GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
! 		      && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
! 			  > UNITS_PER_WORD)
! 		      && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
! 			   / UNITS_PER_WORD)
! 			  != HARD_REGNO_NREGS (REGNO (SUBREG_REG (in)),
! 					       GET_MODE (SUBREG_REG (in)))))))))
      {
        /* This relies on the fact that emit_reload_insns outputs the
  	 instructions for input reloads of type RELOAD_OTHER in the same
--- 1033,1039 ----
    /* Similar issue for (SUBREG constant ...) if it was not handled by the
       code above.  This can happen if SUBREG_WORD != 0.  */
  
!   if (in != 0 && reload_inner_reg_of_subreg (in, inmode))
      {
        /* This relies on the fact that emit_reload_insns outputs the
  	 instructions for input reloads of type RELOAD_OTHER in the same
*************** push_reload (in, out, inloc, outloc, cla
*** 1093,1110 ****
       However, we must reload the inner reg *as well as* the subreg in
       that case.  In this case, the inner reg is an in-out reload.  */
  
!   if (out != 0 && GET_CODE (out) == SUBREG
!       && GET_CODE (SUBREG_REG (out)) == REG
!       && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
!       && (! HARD_REGNO_MODE_OK (REGNO (SUBREG_REG (out)) + SUBREG_WORD (out),
! 				outmode)
! 	  || (GET_MODE_SIZE (outmode) <= UNITS_PER_WORD
! 	      && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
! 		  > UNITS_PER_WORD)
! 	      && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
! 		   / UNITS_PER_WORD)
! 		  != HARD_REGNO_NREGS (REGNO (SUBREG_REG (out)),
! 				       GET_MODE (SUBREG_REG (out)))))))
      {
        /* This relies on the fact that emit_reload_insns outputs the
  	 instructions for output reloads of type RELOAD_OTHER in reverse
--- 1120,1126 ----
       However, we must reload the inner reg *as well as* the subreg in
       that case.  In this case, the inner reg is an in-out reload.  */
  
!   if (out != 0 && reload_inner_reg_of_subreg (out, outmode))
      {
        /* This relies on the fact that emit_reload_insns outputs the
  	 instructions for output reloads of type RELOAD_OTHER in reverse
*************** combine_reloads ()
*** 1655,1660 ****
--- 1671,1677 ----
  		&& ! (GET_CODE (rld[i].in) == REG
  		      && reg_overlap_mentioned_for_reload_p (rld[i].in,
  							     rld[output_reload].out))))
+ 	&& ! reload_inner_reg_of_subreg (rld[i].in, rld[i].inmode)
  	&& (reg_class_size[(int) rld[i].class]
  	    || SMALL_REGISTER_CLASSES)
  	/* We will allow making things slightly worse by combining an







More information about the Gcc-patches mailing list