This is the mail archive of the gcc@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]

Peepholes obsolete / new peepholes


Peepholes obsolete (?)

The peephole definitions in h8300.md cc pre-decrement and
post-increment memory accesses seem to be obsolete. Apparently,
the regarding optimizations are done in an earlier step already.
I temporarily removed those peepholes and all my test cases
still produced optimal code. Also, couldn't find any
different compiler output in a fairly large project.

PATCH:
Clear all current peephole definitions from h8300.md


New Peepholes

Following (admittedly rare) case produced sub-optimal code with
can be improved by new peepholes:

void pushb(char b, char *p)
{
  *--p = b;
}

void pushw(int w, int *p)
{
  *--p = w;
}

compiler output:

_pushb:
    mov.b   r0l,@(-1,r1)
    rts

_pushw:
    mov.w   r0,@(-2,r1)
    rts

The reason for the non-optimal output is that the compiler assumes
it could save one instruction (the decrements). Unfortunately, it
added 2 bytes to the optimal instruction size (the offsets).

after patch:

_pushb:
    mov.b   r0l,@-r1
    rts

_pushw:
    mov.w   r0,@-r1
    rts


PATCH:

add the following to h8300.md

;; Notice a move which could be pre-decremented.

;; byte

(define_peephole2
  [(set (mem:HI (plus:HI (match_operand:HI 1 "register_operand" "r")
(const_int -2)))
        (match_operand:HI 0 "register_operand" "r"))]
  "(find_reg_note (insn, REG_DEAD, operands[1]) && (REGNO(operands[1]) !=
REGNO(operands[0])))"
  [(set (mem:SI (pre_dec:HI (match_dup 1)))
        (match_dup 0))]
  "")

;; word

(define_peephole2
  [(set (mem:QI (plus:HI (match_operand:HI 1 "register_operand" "r")
(const_int -1)))
        (match_operand:QI 0 "register_operand" "r"))]
  "(find_reg_note (insn, REG_DEAD, operands[1]) && (REGNO(operands[1]) !=
REGNO(operands[0])))"
  [(set (mem:QI (pre_dec:HI (match_dup 1)))
        (match_dup 0))]
  "")



           .....
           ô ô )
-----oOOo--(_)---oOOo------

Ralf Guetlein
Biotest Medizintechnik GmbH
Industriestrasse 19
D-63755 Alzenau
Germany
---------------------------
Tel. +49 6023 9487-42
Fax. +49 6023 9487-33
ralf.guetlein@biotest-mt.de
---------------------------



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