> On Jul 13, 2015, at 5:48 PM, Kyrill Tkachov <kyrylo.tkac...@arm.com> wrote:
> 
> Hi all,
> 
> For the testcase in the patch we were generating an extra neg instruction:
>        cmp     w0, wzr
>        csneg   w0, w0, w0, ge
>        neg     w0, w0
>        ret
> 
> instead of the optimal:
>        cmp     w0, wzr
>        csneg   w0, w0, w0, lt
>        ret
> 
> The reason is that combine tries to merge the operation into a negation of an 
> abs.
> I considered teaching combine not to do that but it would require telling it 
> that it shouldn't
> do it if there is a conditional negate instruction. There's no optab for that 
> though :(
> Also, we already advertise that we have an abs optab, even though we expand 
> to a compare and
> a csneg anyway. This patch was the cleanest way I could do this. We just 
> match the neg of an abs
> and generate the same csneg sequence as for normal abs, just with the 
> comparison condition inverted.
> 
> Bootstrapped and tested on aarch64.
> 
> Ok for trunk?
> Thanks,
> Kyrill
> 
> 2015-07-13  Kyrylo Tkachov  <kyrylo.tkac...@arm.com>
> 
>    * config/aarch64/aarch64.md (*absneg2<mode>_insn): New
>    define_and_split.

This pattern is incorrect as you need to say you are clobbering the flags 
register. Otherwise an optimization between combine and the splitter can move 
an instruction between it. Also it might be better to just have a define_split 
rather than a define_insn_and_split. Combine knows how to use define_split 
without being an insn. 

Thanks,
Andrew

> 
> 2015-07-13  Kyrylo Tkachov  <kyrylo.tkac...@arm.com>
> 
>    * gcc.target/aarch64/neg-abs_1.c: New test.
> <abs-neg.patch>

Reply via email to