This patch is to generate more conditional compare instructions in Thumb2
state. Given an example like below,

int f(int i, int j) 
{
  if ( (i == '+') || (j == '-') ) {
    return i;
  } else {
    return j;
  }
}

Without the patch, compiler generates the following codes,

        sub     r2, r0, #43
        rsbs    r3, r2, #0
        adc     r3, r3, r2
        cmp     r1, #45
        it      eq
        orreq   r3, r3, #1
        cmp     r3, #0
        it      eq
        moveq   r0, r1
        bx      lr

With the patch, compiler can generate conditional jump like below,

        cmp     r0, #43
        it      ne
        cmpne   r1, #45
        it      ne
        movne   r0, r1
        bx      lr

The patch is essentially to insert *it* instruction for the following rules
in arm.md,

* cmp_ite0
* cmp_ite1
* cmp_and
* cmp_ior

Tested against arm-none-eabi target and no regression found.

Source code Changelog would be:

2011-07-29  Jiangning Liu  <jiangning....@arm.com>

        * config/arm/arm.md (*ior_scc_scc): Enable for Thumb2 as well.
        (*ior_scc_scc_cmp): Likewise
        (*and_scc_scc): Likewise.
        (*and_scc_scc_cmp): Likewise.
        (*and_scc_scc_nodom): Likewise.
        (*cmp_ite0, *cmp_ite1, *cmp_and, *cmp_ior): Handle Thumb2.

Testsuite Changelog would be:

2011-07-29  Jiangning Liu  <jiangning....@arm.com>

        * gcc.target/arm/thumb2-cond-cmp-1.c: New. Make sure conditional 
        compare can be generated.
        * gcc.target/arm/thumb2-cond-cmp-2.c: Likewise.
        * gcc.target/arm/thumb2-cond-cmp-3.c: Likewise.
        * gcc.target/arm/thumb2-cond-cmp-4.c: Likewise.

Thanks,
-Jiangning

Attachment: fix_cond_cmp.patch
Description: Binary data

Reply via email to