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

Calculating instruction costs

I'm working on a gcc backend for an architecture. The architecture has
instructions for indexed array access; so, ld r0, (r1, r2) is equivalent
to r0 = r1[r2] where r1 is a int32_t*.

I'm representing this in the .md file with the following pattern:

(define_insn "*si_load_indexed"
      (match_operand:SI 0 "register_operand" "=r")
            (match_operand:SI 1 "register_operand" "%r")
            (const_int 4))
          (match_operand:SI 2 "register_operand" "r"))))
  "ld %0, (%2, %1)"
  [(set_attr "length" "4")]

However, the instruction is never actually being emitted. Looking at the
debug output from the instruction combining stage, I see this:

Trying 8, 9 -> 10:
Successfully matched this instruction:
(set (reg:SI 47 [ *_5 ])
    (mem:SI (plus:SI (mult:SI (reg/v:SI 43 [ b ])
                (const_int 4 [0x4]))
            (reg:SI 0 r0 [ a ])) [2 *_5+0 S4 A32]))
rejecting combination of insns 8, 9 and 10
original costs 8 + 4 + 4 = 16
replacement cost 32

Instructions 8, 9 and 10 are:

(insn 8 5 9 2 (set (reg:SI 45)
        (ashift:SI (reg/v:SI 43 [ b ])
            (const_int 2 [0x2]))) test.c:5 15 {ashlsi3}
     (expr_list:REG_DEAD (reg/v:SI 43 [ b ])
(insn 9 8 10 2 (set (reg/f:SI 46)
        (plus:SI (reg/v/f:SI 42 [ a ])
            (reg:SI 45))) test.c:5 13 {addsi3}
     (expr_list:REG_DEAD (reg:SI 45)
        (expr_list:REG_DEAD (reg/v/f:SI 42 [ a ])
(insn 10 9 15 2 (set (reg:SI 47 [ *_5 ])
        (mem:SI (reg/f:SI 46) [2 *_5+0 S4 A32])) test.c:5 6 {*si_load}
     (expr_list:REG_DEAD (reg/f:SI 46)

If I've read this correctly, it indicates that the instruction pattern
has been matched, but the instruction has been rejected due to being
more expensive than the original instructions.

So, how is it calculating the cost of my instruction? Where's it getting
that 32 from (which seems weirdly high)?

Right now all the cost macros are left as the default, which is probably
the root of the problem; but I'm having a lot of trouble getting my head
around them. In the interest of actually getting something to work, are
there any ways of using a simplified cost model where the cost of each
instruction is specified manually in the instruction pattern alongside
the length? (Or even just *using* the length as the cost...)

ââââ ïïïïïïïïïïïïïï âââââ âââââ
â "USER'S MANUAL VERSION 1.0:  The information presented in this
â publication has been carefully for reliability." --- anonymous
â computer hardware manual

Attachment: signature.asc
Description: OpenPGP digital signature

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