From: "Wilco Dijkstra" <wdijkstr@arm.com>
To: "'GCC Patches'" <gcc-patches@gcc.gnu.org>
Subject: RE: [PATCH][AArch64] Use conditional negate for abs expansion
Date: Mon, 27 Apr 2015 13:42:00 -0000 [thread overview]
Message-ID: <000301d080f0$05b46840$111d38c0$@com> (raw)
In-Reply-To:
ping
> -----Original Message-----
> From: Wilco Dijkstra [mailto:wdijkstr@arm.com]
> Sent: 03 March 2015 16:19
> To: GCC Patches
> Subject: [PATCH][AArch64] Use conditional negate for abs expansion
>
> Expand abs into a compare and conditional negate. This is the most obvious expansion, enables
> merging of the comparison into ALU instructions and is faster on all implementations.
> Bootstrapped & regression tested.
>
> int f(int x) { return abs (x + 1); }
>
> Before:
> add w0, w0, 1
> sxtw x0, w0
> eor x1, x0, x0, asr 63
> sub x1, x1, x0, asr 63
> mov x0, x1
> ret
>
> After:
> adds w0, w0, 1
> csneg w0, w0, w0, pl
> ret
>
> ChangeLog:
>
> 2015-03-03 Wilco Dijkstra <wdijkstr@arm.com>
>
> * gcc/config/aarch64/aarch64.md (absdi2): optimize abs expansion.
> (csneg3<mode>_insn): enable expansion of pattern.
> * gcc/testsuite/gcc.target/aarch64/abs_1.c (abs64): update test
> for new abs expansion. (abs64_in_dreg): likewise.
>
> ---
> gcc/config/aarch64/aarch64.md | 33 +++++++-------------------------
> gcc/testsuite/gcc.target/aarch64/abs_1.c | 5 ++---
> 2 files changed, 9 insertions(+), 29 deletions(-)
>
> diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
> index 1f4169e..46b7a63 100644
> --- a/gcc/config/aarch64/aarch64.md
> +++ b/gcc/config/aarch64/aarch64.md
> @@ -2172,35 +2172,16 @@
> [(set_attr "type" "alu_ext")]
> )
>
> -(define_insn_and_split "absdi2"
> - [(set (match_operand:DI 0 "register_operand" "=&r,w")
> - (abs:DI (match_operand:DI 1 "register_operand" "r,w")))]
> +(define_expand "abs<mode>2"
> + [(match_operand:GPI 0 "register_operand" "")
> + (match_operand:GPI 1 "register_operand" "")]
> ""
> - "@
> - #
> - abs\\t%d0, %d1"
> - "reload_completed
> - && GP_REGNUM_P (REGNO (operands[0]))
> - && GP_REGNUM_P (REGNO (operands[1]))"
> - [(const_int 0)]
> {
> - emit_insn (gen_rtx_SET (VOIDmode, operands[0],
> - gen_rtx_XOR (DImode,
> - gen_rtx_ASHIFTRT (DImode,
> - operands[1],
> - GEN_INT (63)),
> - operands[1])));
> - emit_insn (gen_rtx_SET (VOIDmode,
> - operands[0],
> - gen_rtx_MINUS (DImode,
> - operands[0],
> - gen_rtx_ASHIFTRT (DImode,
> - operands[1],
> - GEN_INT (63)))));
> + rtx ccreg = aarch64_gen_compare_reg (LT, operands[1], const0_rtx);
> + rtx x = gen_rtx_LT (VOIDmode, ccreg, const0_rtx);
> + emit_insn (gen_csneg3<mode>_insn (operands[0], x, operands[1], operands[1]));
> DONE;
> }
> - [(set_attr "type" "alu_sreg")
> - (set_attr "simd" "no,yes")]
> )
>
> (define_insn "neg<mode>2"
> @@ -2879,7 +2860,7 @@
> [(set_attr "type" "csel")]
> )
>
> -(define_insn "*csneg3<mode>_insn"
> +(define_insn "csneg3<mode>_insn"
> [(set (match_operand:GPI 0 "register_operand" "=r")
> (if_then_else:GPI
> (match_operand 1 "aarch64_comparison_operation" "")
> diff --git a/gcc/testsuite/gcc.target/aarch64/abs_1.c
> b/gcc/testsuite/gcc.target/aarch64/abs_1.c
> index 938bc84..11f1095 100644
> --- a/gcc/testsuite/gcc.target/aarch64/abs_1.c
> +++ b/gcc/testsuite/gcc.target/aarch64/abs_1.c
> @@ -7,15 +7,14 @@ extern void abort (void);
> long long
> abs64 (long long a)
> {
> - /* { dg-final { scan-assembler "eor\t" } } */
> - /* { dg-final { scan-assembler "sub\t" } } */
> + /* { dg-final { scan-assembler "csneg\t" } } */
> return llabs (a);
> }
>
> long long
> abs64_in_dreg (long long a)
> {
> - /* { dg-final { scan-assembler "abs\td\[0-9\]+, d\[0-9\]+" } } */
> + /* { dg-final { scan-assembler "csneg\t" } } */
> register long long x asm ("d8") = a;
> register long long y asm ("d9");
> asm volatile ("" : : "w" (x));
> --
> 1.9.1
next reply other threads:[~2015-04-27 13:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-27 13:42 Wilco Dijkstra [this message]
2015-04-27 16:26 ` James Greenhalgh
2015-04-27 16:57 ` Wilco Dijkstra
2015-05-14 9:43 ` James Greenhalgh
2015-05-14 13:25 ` Wilco Dijkstra
-- strict thread matches above, loose matches on Subject: below --
2015-03-03 16:19 Wilco Dijkstra
2015-03-04 9:18 ` Maxim Kuvyrkov
2015-03-04 12:31 ` Wilco Dijkstra
2015-03-04 12:49 ` Maxim Kuvyrkov
2015-03-04 15:00 ` Wilco Dijkstra
2015-03-04 15:16 ` Maxim Kuvyrkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='000301d080f0$05b46840$111d38c0$@com' \
--to=wdijkstr@arm.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).