我正在为架构开发 gcc 后端。该架构具有索引数组访问的指令;所以,ld r0, (r1, r2)
相当于r0 = r1[r2]
where r1
is a int32_t*
。
我.md
用以下模式在文件中表示它:
(define_insn "*si_load_indexed"
[
(set
(match_operand:SI 0 "register_operand" "=r")
(mem:SI
(plus:SI
(mult:SI
(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")]
)
但是,该指令实际上从未被发出。查看指令组合阶段的调试输出,我看到:
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
如果我没看错的话,说明指令模式已经匹配,但是指令因为比原来的指令贵而被拒绝了。
那么,它是如何计算我的教学成本的呢?32 是从哪里来的(这看起来有点奇怪)?我如何说服 gcc 实际使用该指令?