This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH][AArch64] Handle -|x| case using a single csneg
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: Kyrill Tkachov <kyrylo dot tkachov at arm dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Marcus Shawcroft <marcus dot shawcroft at arm dot com>, Richard Earnshaw <Richard dot Earnshaw at arm dot com>, James Greenhalgh <james dot greenhalgh at arm dot com>
- Date: Mon, 13 Jul 2015 19:38:00 -0500
- Subject: Re: [PATCH][AArch64] Handle -|x| case using a single csneg
- Authentication-results: sourceware.org; auth=none
- References: <55A38963 dot 6080408 at arm dot com>
On Mon, Jul 13, 2015 at 10:48:19AM +0100, Kyrill Tkachov wrote:
> 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.
Before combine, you have two insns, a negation and an abs, so that is
not so very strange :-)
Some archs have actual nabs insns btw (for floating point, anyway).
Archs without abs or conditional assignment, and with cheap branches,
get a branch around a neg followed by another neg, at expand time.
This then isn't optimised away either.
So I'd say expand should be made a bit smarter for this. Failing
that, your approach looks fine to me -- assuming you want to have a
fake "abs" insn at all.
On to the patch...
> +;; Combine will try merging (c > 0 ? -x : x) into (-|x|). This isn't a good
"x > 0" here.
Segher