This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH: PR target/44072] Replace "cmp r0, -1" by "adds r0, 1" in thumb2
- From: Richard Earnshaw <rearnsha at arm dot com>
- To: Carrot Wei <carrot at google dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 13 May 2010 08:28:47 +0100
- Subject: Re: [PATCH: PR target/44072] Replace "cmp r0, -1" by "adds r0, 1" in thumb2
- References: <v2o7587b291005120143sb7c92b41l976e1d631eb8bc1b@mail.gmail.com>
On Wed, 2010-05-12 at 16:43 +0800, Carrot Wei wrote:
> Hi
>
> Both "cmp r0, -1" and "adds r0, 1" have the same effect when used to set
> conditions for following branch. But adds with small positive immediate is a
> 16 bit instruction and cmp with negative immediate is a 32 bit instruction. So
> we prefer adds in thumb2.
>
> Thumb1 already has an insn pattern "cbranchsi4_scratch" to do this, this patch
> adds the corresponding insn pattern for thumb2.
>
> +
> +(define_insn "thumb2_cbranchsi4_scratch"
> + [(set (pc) (if_then_else
> + (match_operator 4 "arm_comparison_operator"
> + [(match_operand:SI 1 "s_register_operand" "l,?h,0")
> + (match_operand:SI 2 "thumb1_cmpneg_operand" "Pt,Ps,Ps")])
You should put the constrains in the order that they are preferred,
rather than trying to force the behaviour with '?'. So the constraints
for op1 should be "l,0,h" and the rest of the pattern adjusted to match.
OK with that change.
R.