This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/43597] Move and compare with 0 can be combined
- From: "steven at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 31 Mar 2010 14:59:10 -0000
- Subject: [Bug target/43597] Move and compare with 0 can be combined
- References: <bug-43597-17659@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from steven at gcc dot gnu dot org 2010-03-31 14:59 -------
In .final, the insns look like this:
@(insn:TI 9 7 8 t.c:8 (set (reg:CC 24 cc)
@ (compare:CC (reg:SI 0 r0 [orig:134 f ] [134])
@ (const_int 0 [0x0]))) 220 {*arm_cmpsi_insn} (expr_list:REG_DEAD
(reg:SI 0 r0 [orig:134 f ] [134])
@ (nil)))
cmp r0, #0 @ 9 *arm_cmpsi_insn/1 [length = 4]
@(insn 8 9 10 t.c:7 (set (reg/v:SI 5 r5 [orig:134 f ] [134])
@ (reg:SI 0 r0)) 658 {*thumb2_movsi_insn} (nil))
mov r5, r0 @ 8 *thumb2_movsi_insn/1 [length = 4]
This, AFAICT, would match with the pattern and constraints of movsi_compare0:
;; If copying one reg to another we can set the condition codes according to
;; its value. Such a move is common after a return from subroutine and the
;; result is being tested against zero.
(define_insn "*movsi_compare0"
[(set (reg:CC CC_REGNUM)
(compare:CC (match_operand:SI 1 "s_register_operand" "0,r")
(const_int 0)))
(set (match_operand:SI 0 "s_register_operand" "=r,r")
(match_dup 1))]
"TARGET_32BIT"
"@
cmp%?\\t%0, #0
sub%.\\t%0, %1, #0"
[(set_attr "conds" "set")]
)
But this insns can probably only be formed in the .combine pass, since (to the
best of my knowledge) we don't construct multiple-set insns in any other pass.
In the .combine pass, the two insns look like this (obviously reversed, as you
could already suspect from the insns numbers 9 and 8 above):
(insn 8 7 9 2 t.c:7 (set (reg/v:SI 134 [ f ])
(reg:SI 0 r0)) 658 {*thumb2_movsi_insn} (expr_list:REG_DEAD (reg:SI 0
r0)
(nil)))
(insn 9 8 10 2 t.c:8 (set (reg:CC 24 cc)
(compare:CC (reg/v:SI 134 [ f ])
(const_int 0 [0x0]))) 220 {*arm_cmpsi_insn} (nil))
But combine does not even try to combine these two insns:
------------
...
insn_cost 24: 0
Trying 9 -> 10:
Failed to match this instruction:
(set (pc)
(if_then_else (lt (reg/v:SI 134 [ f ])
(const_int 0 [0x0]))
(label_ref:SI 29)
(pc)))
foo4
...
------------
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43597