[PATCH][AArch64] Improve comparison with complex immediates followed by branch/cset

Kyrill Tkachov kyrylo.tkachov@arm.com
Tue Oct 13 08:21:00 GMT 2015


On 08/10/15 09:54, Kyrill Tkachov wrote:
> Hi all,
>
> This patch slightly improves sequences where we want to compare against a complex immediate and branch against the result
> or perform a cset on it.
> This means transforming sequences of mov+movk+cmp+branch into sub+subs+branch.
> Similar for cset. Unfortunately I can't just do this by simply matching a (compare (reg) (const_int)) rtx because
> this transformation is only valid for equal/not equal comparisons, not greater than/less than ones but the compare instruction
> pattern only has the general CC mode. We need to also match the use of the condition code.
>
> I've done this by creating a splitter for the conditional jump where the condition is the comparison between the register
> and the complex immediate and splitting it into the sub+subs+condjump sequence. Similar for the cstore pattern.
> Thankfully we don't split immediate moves until later in the optimization pipeline so combine can still try the right patterns.
> With this patch for the example code:
> void g(void);
> void f8(int x)
> {
>      if (x != 0x123456) g();
> }
>
> I get:
> f8:
>           sub     w0, w0, #1191936
>           subs    w0, w0, #1110
>           beq     .L1
>           b       g
>           .p2align 3
> .L1:
>           ret
>
> instead of the previous:
> f8:
>           mov     w1, 13398
>           movk    w1, 0x12, lsl 16
>           cmp     w0, w1
>           beq     .L1
>           b       g
>           .p2align 3
> .L1:
>           ret
>
>
> The condjump case triggered 130 times across all of SPEC2006 which is, admittedly, not much
> whereas the cstore case didn't trigger at all. However, the included testcase in the patch
> demonstrates the kind of code that it would trigger on.
>
> Bootstrapped and tested on aarch64.
>
> Ok for trunk?

There's a few changes I'd like to make to this patch and I'll post an updated version when it's ready.
So no need to review this version, besides getting the general idea of the transformation...

Sorry for the noise,
Kyrill


> Thanks,
> Kyrill
>
>
> 2015-10-08  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
>
>       * config/aarch64/aarch64.md (*condjump): Rename to...
>       (condjump): ... This.
>       (*compare_condjump<mode>): New define_insn_and_split.
>       (*compare_cstore<mode>_insn): Likewise.
>       (*cstore<mode>_insn): Rename to...
>       (cstore<mode>_insn): ... This.
>       * config/aarch64/iterators.md (CMP): Handle ne code.
>       * config/aarch64/predicates.md (aarch64_imm24): New predicate.
>
> 2015-10-08  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
>
>       * gcc.target/aarch64/cmpimm_branch_1.c: New test.
>       * gcc.target/aarch64/cmpimm_cset_1.c: Likewise.



More information about the Gcc-patches mailing list