[PATCH][AArch64] Handle -|x| case using a single csneg
Segher Boessenkool
segher@kernel.crashing.org
Tue Jul 14 00:38:00 GMT 2015
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
More information about the Gcc-patches
mailing list