AVR peephole2 fixes

Marek Michalkiewicz marekm@linux.org.pl
Mon Jan 1 09:29:00 GMT 2001


OK to commit?

2001-01-01  Marek Michalkiewicz  <marekm@linux.org.pl>
	    Denis Chertykov  <denisc@overta.ru>

	* config/avr/avr-protos.h (avr_peep2_scratch_safe): Prototype.
	* config/avr/avr.c (avr_peep2_scratch_safe): New function.
	* config/avr/avr.md (all peepholes that request a scratch register):
	Call it, FAIL the peephole if not safe (in interrupt functions).

Index: config/avr/avr-protos.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/avr/avr-protos.h,v
retrieving revision 1.10
diff -c -3 -p -r1.10 avr-protos.h
*** avr-protos.h	2000/11/19 07:10:54	1.10
--- avr-protos.h	2001/01/01 17:25:53
*************** extern const char * lshrsi3_out PARAMS (
*** 111,116 ****
--- 111,117 ----
  
  extern void avr_output_bld PARAMS ((rtx operands[], int bit_nr));
  extern void avr_output_addr_vec_elt PARAMS ((FILE *stream, int value));
+ extern int  avr_peep2_scratch_safe  PARAMS ((rtx scratch));
  
  extern enum reg_class preferred_reload_class PARAMS ((rtx x,
  						     enum reg_class class));
Index: config/avr/avr.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/avr/avr.c,v
retrieving revision 1.35
diff -c -3 -p -r1.35 avr.c
*** avr.c	2000/12/23 19:58:17	1.35
--- avr.c	2001/01/01 17:26:06
*************** avr_output_addr_vec_elt (stream, value)
*** 5374,5376 ****
--- 5374,5397 ----
    jump_tables_size++;
  }
  
+ int
+ avr_peep2_scratch_safe (scratch)
+      rtx scratch;
+ {
+   if ((interrupt_function_p (current_function_decl)
+        || signal_function_p (current_function_decl))
+       && leaf_function_p ())
+     {
+       int first_reg = true_regnum (scratch);
+       int last_reg = first_reg + GET_MODE_SIZE (GET_MODE (scratch)) - 1;
+       int reg;
+ 
+       for (reg = first_reg; reg <= last_reg; reg++)
+ 	{
+ 	  if (!regs_ever_live[reg])
+ 	    return 0;
+ 	}
+     }
+   return 1;
+ }
+ 
Index: config/avr/avr.md
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/avr/avr.md,v
retrieving revision 1.22
diff -c -3 -p -r1.22 avr.md
*** avr.md	2000/12/20 18:49:22	1.22
--- avr.md	2001/01/01 17:26:11
***************
*** 200,206 ****
      && test_hard_reg_class (NO_LD_REGS, operands[0]))"
    [(parallel [(set (match_dup 0) (match_dup 1))
  	      (clobber (match_dup 2))])]
!   "")
  
  ;;============================================================================
  ;; move word (16 bit)
--- 200,209 ----
      && test_hard_reg_class (NO_LD_REGS, operands[0]))"
    [(parallel [(set (match_dup 0) (match_dup 1))
  	      (clobber (match_dup 2))])]
!   "{
!   if (!avr_peep2_scratch_safe (operands[2]))
!     FAIL;
! }")
  
  ;;============================================================================
  ;; move word (16 bit)
***************
*** 228,234 ****
      && test_hard_reg_class (NO_LD_REGS, operands[0]))"
    [(parallel [(set (match_dup 0) (match_dup 1))
  	      (clobber (match_dup 2))])]
!   "")
  
  ;; '*' because it is not used in rtl generation, only in above peephole
  (define_insn "*reload_inhi"
--- 231,240 ----
      && test_hard_reg_class (NO_LD_REGS, operands[0]))"
    [(parallel [(set (match_dup 0) (match_dup 1))
  	      (clobber (match_dup 2))])]
!   "{
!   if (!avr_peep2_scratch_safe (operands[2]))
!     FAIL;
! }")
  
  ;; '*' because it is not used in rtl generation, only in above peephole
  (define_insn "*reload_inhi"
***************
*** 276,282 ****
      && test_hard_reg_class (NO_LD_REGS, operands[0]))"
    [(parallel [(set (match_dup 0) (match_dup 1))
  	      (clobber (match_dup 2))])]
!   "")
  
  ;; '*' because it is not used in rtl generation.
  (define_insn "*reload_insi"
--- 282,291 ----
      && test_hard_reg_class (NO_LD_REGS, operands[0]))"
    [(parallel [(set (match_dup 0) (match_dup 1))
  	      (clobber (match_dup 2))])]
!   "{
!   if (!avr_peep2_scratch_safe (operands[2]))
!     FAIL;
! }")
  
  ;; '*' because it is not used in rtl generation.
  (define_insn "*reload_insi"
***************
*** 929,935 ****
    ""
    [(parallel [(set (match_dup 0) (ashift:HI (match_dup 1) (match_dup 2)))
  	      (clobber (match_dup 3))])]
!   "")
  
  (define_insn "*ashlhi3_const"
    [(set (match_operand:HI 0 "register_operand"            "=r,r,r,r")
--- 938,947 ----
    ""
    [(parallel [(set (match_dup 0) (ashift:HI (match_dup 1) (match_dup 2)))
  	      (clobber (match_dup 3))])]
!   "{
!   if (!avr_peep2_scratch_safe (operands[3]))
!     FAIL;
! }")
  
  (define_insn "*ashlhi3_const"
    [(set (match_operand:HI 0 "register_operand"            "=r,r,r,r")
***************
*** 949,955 ****
    ""
    [(parallel [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
  	      (clobber (match_dup 3))])]
!   "")
  
  (define_insn "*ashlsi3_const"
    [(set (match_operand:SI 0 "register_operand"            "=r,r,r")
--- 961,970 ----
    ""
    [(parallel [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
  	      (clobber (match_dup 3))])]
!   "{
!   if (!avr_peep2_scratch_safe (operands[3]))
!     FAIL;
! }")
  
  (define_insn "*ashlsi3_const"
    [(set (match_operand:SI 0 "register_operand"            "=r,r,r")
***************
*** 1001,1007 ****
    ""
    [(parallel [(set (match_dup 0) (ashiftrt:HI (match_dup 1) (match_dup 2)))
  	      (clobber (match_dup 3))])]
!   "")
  
  (define_insn "*ashrhi3_const"
    [(set (match_operand:HI 0 "register_operand"              "=r,r,r,r")
--- 1016,1025 ----
    ""
    [(parallel [(set (match_dup 0) (ashiftrt:HI (match_dup 1) (match_dup 2)))
  	      (clobber (match_dup 3))])]
!   "{
!   if (!avr_peep2_scratch_safe (operands[3]))
!     FAIL;
! }")
  
  (define_insn "*ashrhi3_const"
    [(set (match_operand:HI 0 "register_operand"              "=r,r,r,r")
***************
*** 1021,1027 ****
    ""
    [(parallel [(set (match_dup 0) (ashiftrt:SI (match_dup 1) (match_dup 2)))
  	      (clobber (match_dup 3))])]
!   "")
  
  (define_insn "*ashrsi3_const"
    [(set (match_operand:SI 0 "register_operand"              "=r,r,r")
--- 1039,1048 ----
    ""
    [(parallel [(set (match_dup 0) (ashiftrt:SI (match_dup 1) (match_dup 2)))
  	      (clobber (match_dup 3))])]
!   "{
!   if (!avr_peep2_scratch_safe (operands[3]))
!     FAIL;
! }")
  
  (define_insn "*ashrsi3_const"
    [(set (match_operand:SI 0 "register_operand"              "=r,r,r")
***************
*** 1073,1079 ****
    ""
    [(parallel [(set (match_dup 0) (lshiftrt:HI (match_dup 1) (match_dup 2)))
  	      (clobber (match_dup 3))])]
!   "")
  
  (define_insn "*lshrhi3_const"
    [(set (match_operand:HI 0 "register_operand"              "=r,r,r,r")
--- 1094,1103 ----
    ""
    [(parallel [(set (match_dup 0) (lshiftrt:HI (match_dup 1) (match_dup 2)))
  	      (clobber (match_dup 3))])]
!   "{
!   if (!avr_peep2_scratch_safe (operands[3]))
!     FAIL;
! }")
  
  (define_insn "*lshrhi3_const"
    [(set (match_operand:HI 0 "register_operand"              "=r,r,r,r")
***************
*** 1093,1099 ****
    ""
    [(parallel [(set (match_dup 0) (lshiftrt:SI (match_dup 1) (match_dup 2)))
  	      (clobber (match_dup 3))])]
!   "")
  
  (define_insn "*lshrsi3_const"
    [(set (match_operand:SI 0 "register_operand"              "=r,r,r")
--- 1117,1126 ----
    ""
    [(parallel [(set (match_dup 0) (lshiftrt:SI (match_dup 1) (match_dup 2)))
  	      (clobber (match_dup 3))])]
!   "{
!   if (!avr_peep2_scratch_safe (operands[3]))
!     FAIL;
! }")
  
  (define_insn "*lshrsi3_const"
    [(set (match_operand:SI 0 "register_operand"              "=r,r,r")



More information about the Gcc-patches mailing list