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 PR18251: avr reload failure


This patch fixes the reload issue of PR18251 on the avr target. It also fixes a similar issue found by Björn Haase <bjoern.m.haase@web.de> as a small regression on Roger Sayles rtx_cost patch.

The patch changes BLK movmemhi pattern into an RTL expansion "move loop". Thus exposing the internals to gcc and removing the need for the specific BLK insn patterns that caused the reload failure.

PR target/18251
* avr.md movmemhi: rewritten as RTL loop
(*movmemqi_insn):deleted
(*movmemhi):deleted
Please can somebody comit this change.



Index: avr.md =================================================================== RCS file: /cvsroot/gcc/gcc/gcc/config/avr/avr.md,v retrieving revision 1.49 diff -c -3 -p -r1.49 avr.md *** avr.md 27 Jan 2005 18:22:25 -0000 1.49 --- avr.md 14 Feb 2005 23:09:06 -0000 *************** *** 344,419 ****


;;========================================================================= ;; move string (like memcpy)

  (define_expand "movmemhi"
    [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
          (match_operand:BLK 1 "memory_operand" ""))
         (use (match_operand:HI 2 "const_int_operand" ""))
         (use (match_operand:HI 3 "const_int_operand" ""))
!         (clobber (match_scratch:HI 4 ""))
!         (clobber (match_scratch:HI 5 ""))
!         (clobber (match_dup 6))])]
    ""
    "{
!   rtx addr0, addr1;
!   int cnt8;
    enum machine_mode mode;

! if (GET_CODE (operands[2]) != CONST_INT)
! FAIL;
! cnt8 = byte_immediate_operand (operands[2], GET_MODE (operands[2]));
! mode = cnt8 ? QImode : HImode;
! operands[6] = gen_rtx_SCRATCH (mode);
! operands[2] = copy_to_mode_reg (mode,
! gen_int_mode (INTVAL (operands[2]), mode));
! addr0 = copy_to_mode_reg (Pmode, XEXP (operands[0], 0));
! addr1 = copy_to_mode_reg (Pmode, XEXP (operands[1], 0));


-   operands[0] = gen_rtx_MEM (BLKmode, addr0);
-   operands[1] = gen_rtx_MEM (BLKmode, addr1);
  }")

- (define_insn "*movmemqi_insn"
- [(set (mem:BLK (match_operand:HI 0 "register_operand" "e"))
- (mem:BLK (match_operand:HI 1 "register_operand" "e")))
- (use (match_operand:QI 2 "register_operand" "r"))
- (use (match_operand:QI 3 "const_int_operand" "i"))
- (clobber (match_scratch:HI 4 "=0"))
- (clobber (match_scratch:HI 5 "=1"))
- (clobber (match_scratch:QI 6 "=2"))]
- ""
- "ld __tmp_reg__,%a1+
- st %a0+,__tmp_reg__
- dec %2
- brne .-8"
- [(set_attr "length" "4")
- (set_attr "cc" "clobber")])
-
- (define_insn "*movmemhi"
- [(set (mem:BLK (match_operand:HI 0 "register_operand" "e,e"))
- (mem:BLK (match_operand:HI 1 "register_operand" "e,e")))
- (use (match_operand:HI 2 "register_operand" "!w,d"))
- (use (match_operand:HI 3 "const_int_operand" ""))
- (clobber (match_scratch:HI 4 "=0,0"))
- (clobber (match_scratch:HI 5 "=1,1"))
- (clobber (match_scratch:HI 6 "=2,2"))]
- ""
- "*{
- if (which_alternative==0)
- return (AS2 (ld,__tmp_reg__,%a1+) CR_TAB
- AS2 (st,%a0+,__tmp_reg__) CR_TAB
- AS2 (sbiw,%A2,1) CR_TAB
- AS1 (brne,.-8));
- else
- return (AS2 (ld,__tmp_reg__,%a1+) CR_TAB
- AS2 (st,%a0+,__tmp_reg__) CR_TAB
- AS2 (subi,%A2,1) CR_TAB
- AS2 (sbci,%B2,0) CR_TAB
- AS1 (brne,.-10));
- }"
- [(set_attr "length" "4,5")
- (set_attr "cc" "clobber,clobber")])
-
;; =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0
;; memset (%0, 0, %1)


--- 344,418 ----


;;========================================================================= ;; move string (like memcpy) + ;; implement as RTL loop

  (define_expand "movmemhi"
    [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
          (match_operand:BLK 1 "memory_operand" ""))
         (use (match_operand:HI 2 "const_int_operand" ""))
         (use (match_operand:HI 3 "const_int_operand" ""))
! ])]
    ""
    "{
!   int cnt8, prob;
    enum machine_mode mode;

! rtx label = gen_label_rtx ();
!
! /*copy pointers into new psuedos - they will be changed*/
! rtx addr0 = copy_to_mode_reg (Pmode, XEXP (operands[0], 0));
! rtx addr1 = copy_to_mode_reg (Pmode, XEXP (operands[1], 0));
!
! /* create rtx for tmp register - we use this as scratch*/
! rtx tmp_reg_rtx = gen_rtx_REG (QImode, TMP_REGNO);
!
! /*if loop count is constant, try to use QImode counter */
! if (GET_CODE (operands[2]) == CONST_INT)
! {
! /* work out branch probability for latter use */
! prob=REG_BR_PROB_BASE-REG_BR_PROB_BASE/INTVAL (operands[2]);
! /*see if constant fit 8 bits */
! cnt8 = byte_immediate_operand (operands[2], GET_MODE (operands[2]));
! mode = cnt8 ? QImode : HImode;
! /*create loop counter register */
! operands[2] = copy_to_mode_reg (mode,gen_int_mode (INTVAL (operands[2]), mode));
! }
! else
! {
! /* not a constant, use HImode counter*/
! mode=HImode;
! operands[2] = copy_to_mode_reg (HImode,operands[2]);
! /*guess probability*/
! prob=REG_BR_PROB_BASE*95/100;
! }
!
! /* now create RTL code for move loop*/
! /* label at top of loop*/
! emit_label (label);
!
! /*move one byte into scratch and inc pointer*/
! emit_move_insn ( tmp_reg_rtx,gen_rtx_MEM(QImode,addr1));
! emit_move_insn (addr1, gen_rtx_PLUS(Pmode,addr1,const1_rtx));
!
! /*move scratch into mem and inc other pointer*/
! emit_move_insn (gen_rtx_MEM(QImode,addr0),tmp_reg_rtx );
! emit_move_insn (addr0, gen_rtx_PLUS(Pmode,addr0,const1_rtx));
!
! /*decrement count */
! emit_move_insn (operands[2], gen_rtx_PLUS(mode,operands[2],constm1_rtx));
!
! /*compare with zero and jump if not equal*/
! emit_cmp_and_jump_insns (operands[2], const0_rtx, NE, NULL_RTX, mode, 1,
! label);
! /* set jump probability based on loop count */ ! rtx jump = get_last_insn ();
! REG_NOTES (jump) = gen_rtx_EXPR_LIST (REG_BR_PROB,
! GEN_INT (prob),
! REG_NOTES (jump));
! DONE;


}")

;; =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0
;; memset (%0, 0, %1)



***** CVS exited normally with code 1 *****


Iterating directories...
Diff'ing new files locally...
Added new: pr18251.pch
Added new: tieable.pch
Diff'ing modified files against repository...
Added mod: avr.h
Added mod: avr.md
D:/cvsroot/gcc/gcc/config/avr/patch.txt created. Done!
cvs -z9 -r -q diff -c3p -- avr.h (in directory D:\cvsroot\gcc\gcc\config\avr\)
Index: avr.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/avr/avr.h,v
retrieving revision 1.110
diff -c -3 -p -r1.110 avr.h
*** avr.h 25 Dec 2004 22:20:04 -0000 1.110
--- avr.h 14 Feb 2005 23:08:18 -0000
*************** extern int avr_asm_only_p;
*** 216,222 ****


#define HARD_REGNO_MODE_OK(REGNO, MODE) avr_hard_regno_mode_ok(REGNO, MODE)

! #define MODES_TIEABLE_P(MODE1, MODE2) 0

  enum reg_class {
    NO_REGS,
--- 216,222 ----

#define HARD_REGNO_MODE_OK(REGNO, MODE) avr_hard_regno_mode_ok(REGNO, MODE)

! #define MODES_TIEABLE_P(MODE1, MODE2) 1

  enum reg_class {
    NO_REGS,

***** CVS exited normally with code 1 *****

Saved settings for D:\cvsroot successfully...
Saved settings for D:\cvsroot successfully...
cvs -z9 -r -q diff -c3p -- avr.md (in directory D:\cvsroot\gcc\gcc\config\avr\)
Index: avr.md
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/avr/avr.md,v
retrieving revision 1.49
diff -c -3 -p -r1.49 avr.md
*** avr.md 27 Jan 2005 18:22:25 -0000 1.49
--- avr.md 14 Feb 2005 23:09:06 -0000
***************
*** 344,419 ****



;;========================================================================= ;; move string (like memcpy)

  (define_expand "movmemhi"
    [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
          (match_operand:BLK 1 "memory_operand" ""))
         (use (match_operand:HI 2 "const_int_operand" ""))
         (use (match_operand:HI 3 "const_int_operand" ""))
!         (clobber (match_scratch:HI 4 ""))
!         (clobber (match_scratch:HI 5 ""))
!         (clobber (match_dup 6))])]
    ""
    "{
!   rtx addr0, addr1;
!   int cnt8;
    enum machine_mode mode;

! if (GET_CODE (operands[2]) != CONST_INT)
! FAIL;
! cnt8 = byte_immediate_operand (operands[2], GET_MODE (operands[2]));
! mode = cnt8 ? QImode : HImode;
! operands[6] = gen_rtx_SCRATCH (mode);
! operands[2] = copy_to_mode_reg (mode,
! gen_int_mode (INTVAL (operands[2]), mode));
! addr0 = copy_to_mode_reg (Pmode, XEXP (operands[0], 0));
! addr1 = copy_to_mode_reg (Pmode, XEXP (operands[1], 0));


-   operands[0] = gen_rtx_MEM (BLKmode, addr0);
-   operands[1] = gen_rtx_MEM (BLKmode, addr1);
  }")

- (define_insn "*movmemqi_insn"
- [(set (mem:BLK (match_operand:HI 0 "register_operand" "e"))
- (mem:BLK (match_operand:HI 1 "register_operand" "e")))
- (use (match_operand:QI 2 "register_operand" "r"))
- (use (match_operand:QI 3 "const_int_operand" "i"))
- (clobber (match_scratch:HI 4 "=0"))
- (clobber (match_scratch:HI 5 "=1"))
- (clobber (match_scratch:QI 6 "=2"))]
- ""
- "ld __tmp_reg__,%a1+
- st %a0+,__tmp_reg__
- dec %2
- brne .-8"
- [(set_attr "length" "4")
- (set_attr "cc" "clobber")])
-
- (define_insn "*movmemhi"
- [(set (mem:BLK (match_operand:HI 0 "register_operand" "e,e"))
- (mem:BLK (match_operand:HI 1 "register_operand" "e,e")))
- (use (match_operand:HI 2 "register_operand" "!w,d"))
- (use (match_operand:HI 3 "const_int_operand" ""))
- (clobber (match_scratch:HI 4 "=0,0"))
- (clobber (match_scratch:HI 5 "=1,1"))
- (clobber (match_scratch:HI 6 "=2,2"))]
- ""
- "*{
- if (which_alternative==0)
- return (AS2 (ld,__tmp_reg__,%a1+) CR_TAB
- AS2 (st,%a0+,__tmp_reg__) CR_TAB
- AS2 (sbiw,%A2,1) CR_TAB
- AS1 (brne,.-8));
- else
- return (AS2 (ld,__tmp_reg__,%a1+) CR_TAB
- AS2 (st,%a0+,__tmp_reg__) CR_TAB
- AS2 (subi,%A2,1) CR_TAB
- AS2 (sbci,%B2,0) CR_TAB
- AS1 (brne,.-10));
- }"
- [(set_attr "length" "4,5")
- (set_attr "cc" "clobber,clobber")])
-
;; =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0
;; memset (%0, 0, %1)


--- 344,418 ----


;;========================================================================= ;; move string (like memcpy) + ;; implement as RTL loop

  (define_expand "movmemhi"
    [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
          (match_operand:BLK 1 "memory_operand" ""))
         (use (match_operand:HI 2 "const_int_operand" ""))
         (use (match_operand:HI 3 "const_int_operand" ""))
! ])]
    ""
    "{
!   int cnt8, prob;
    enum machine_mode mode;

! rtx label = gen_label_rtx ();
!
! /*copy pointers into new psuedos - they will be changed*/
! rtx addr0 = copy_to_mode_reg (Pmode, XEXP (operands[0], 0));
! rtx addr1 = copy_to_mode_reg (Pmode, XEXP (operands[1], 0));
!
! /* create rtx for tmp register - we use this as scratch*/
! rtx tmp_reg_rtx = gen_rtx_REG (QImode, TMP_REGNO);
!
! /*if loop count is constant, try to use QImode counter */
! if (GET_CODE (operands[2]) == CONST_INT)
! {
! /* work out branch probability for latter use */
! prob=REG_BR_PROB_BASE-REG_BR_PROB_BASE/INTVAL (operands[2]);
! /*see if constant fit 8 bits */
! cnt8 = byte_immediate_operand (operands[2], GET_MODE (operands[2]));
! mode = cnt8 ? QImode : HImode;
! /*create loop counter register */
! operands[2] = copy_to_mode_reg (mode,gen_int_mode (INTVAL (operands[2]), mode));
! }
! else
! {
! /* not a constant, use HImode counter*/
! mode=HImode;
! operands[2] = copy_to_mode_reg (HImode,operands[2]);
! /*guess probability*/
! prob=REG_BR_PROB_BASE*95/100;
! }
!
! /* now create RTL code for move loop*/
! /* label at top of loop*/
! emit_label (label);
!
! /*move one byte into scratch and inc pointer*/
! emit_move_insn ( tmp_reg_rtx,gen_rtx_MEM(QImode,addr1));
! emit_move_insn (addr1, gen_rtx_PLUS(Pmode,addr1,const1_rtx));
!
! /*move scratch into mem and inc other pointer*/
! emit_move_insn (gen_rtx_MEM(QImode,addr0),tmp_reg_rtx );
! emit_move_insn (addr0, gen_rtx_PLUS(Pmode,addr0,const1_rtx));
!
! /*decrement count */
! emit_move_insn (operands[2], gen_rtx_PLUS(mode,operands[2],constm1_rtx));
!
! /*compare with zero and jump if not equal*/
! emit_cmp_and_jump_insns (operands[2], const0_rtx, NE, NULL_RTX, mode, 1,
! label);
! /* set jump probability based on loop count */ ! rtx jump = get_last_insn ();
! REG_NOTES (jump) = gen_rtx_EXPR_LIST (REG_BR_PROB,
! GEN_INT (prob),
! REG_NOTES (jump));
! DONE;


}")

;; =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0
;; memset (%0, 0, %1)





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