[PATCH, ARM] Generate conditional compares in Thumb2 state

Jiangning Liu jiangning.liu@arm.com
Wed Aug 3 07:48:00 GMT 2011


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.liu@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.liu@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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix_cond_cmp.patch
Type: application/octet-stream
Size: 11715 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20110803/336945db/attachment.obj>


More information about the Gcc-patches mailing list