public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/2] LoongArch: NFC: Deduplicate crc instruction defines
@ 2024-02-26  4:28 Xi Ruoyao
  2024-02-26  4:28 ` [PATCH 2/2] LoongArch: Remove unneeded sign extension after crc/crcc instructions Xi Ruoyao
  2024-02-26 10:07 ` [PATCH 1/2] LoongArch: NFC: Deduplicate crc instruction defines chenglulu
  0 siblings, 2 replies; 3+ messages in thread
From: Xi Ruoyao @ 2024-02-26  4:28 UTC (permalink / raw)
  To: gcc-patches; +Cc: chenglulu, i, xuchenghua, Xi Ruoyao

Introduce an iterator for UNSPEC_CRC and UNSPEC_CRCC to make the next
change easier.

gcc/ChangeLog:

	* config/loongarch/loongarch.md (CRC): New define_int_iterator.
	(crc): New define_int_attr.
	(loongarch_crc_w_<size>_w, loongarch_crcc_w_<size>_w): Unify
	into ...
	(loongarch_<crc>_w_<size>_w): ... here.
---
 gcc/config/loongarch/loongarch.md | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
index 2ce7a151880..4ded1b3a117 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -4251,24 +4251,16 @@ (define_peephole2
 
 
 (define_mode_iterator QHSD [QI HI SI DI])
+(define_int_iterator CRC [UNSPEC_CRC UNSPEC_CRCC])
+(define_int_attr crc [(UNSPEC_CRC "crc") (UNSPEC_CRCC "crcc")])
 
-(define_insn "loongarch_crc_w_<size>_w"
+(define_insn "loongarch_<crc>_w_<size>_w"
   [(set (match_operand:SI 0 "register_operand" "=r")
 	(unspec:SI [(match_operand:QHSD 1 "register_operand" "r")
 		   (match_operand:SI 2 "register_operand" "r")]
-		     UNSPEC_CRC))]
+		     CRC))]
   ""
-  "crc.w.<size>.w\t%0,%1,%2"
-  [(set_attr "type" "unknown")
-   (set_attr "mode" "<MODE>")])
-
-(define_insn "loongarch_crcc_w_<size>_w"
-  [(set (match_operand:SI 0 "register_operand" "=r")
-	(unspec:SI [(match_operand:QHSD 1 "register_operand" "r")
-		   (match_operand:SI 2 "register_operand" "r")]
-		     UNSPEC_CRCC))]
-  ""
-  "crcc.w.<size>.w\t%0,%1,%2"
+  "<crc>.w.<size>.w\t%0,%1,%2"
   [(set_attr "type" "unknown")
    (set_attr "mode" "<MODE>")])
 
-- 
2.44.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] LoongArch: Remove unneeded sign extension after crc/crcc instructions
  2024-02-26  4:28 [PATCH 1/2] LoongArch: NFC: Deduplicate crc instruction defines Xi Ruoyao
@ 2024-02-26  4:28 ` Xi Ruoyao
  2024-02-26 10:07 ` [PATCH 1/2] LoongArch: NFC: Deduplicate crc instruction defines chenglulu
  1 sibling, 0 replies; 3+ messages in thread
From: Xi Ruoyao @ 2024-02-26  4:28 UTC (permalink / raw)
  To: gcc-patches; +Cc: chenglulu, i, xuchenghua, Xi Ruoyao

The specification of crc/crcc instructions is clear that the output is
sign-extended to GRLEN.  Add a define_insn to tell the compiler this
fact and allow it to remove the unneeded sign extension on crc/crcc
output.  As crc/crcc instructions are usually used in a tight loop,
this should produce a significant performance gain.

gcc/ChangeLog:

	* config/loongarch/loongarch.md
	(loongarch_<crc>_w_<size>_w_extended): New define_insn.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/crc-sext.c: New test;
---

Bootstrapped and regtested on loongarch64-linux-gnu.  Ok for trunk?

 gcc/config/loongarch/loongarch.md             | 11 +++++++++++
 gcc/testsuite/gcc.target/loongarch/crc-sext.c | 13 +++++++++++++
 2 files changed, 24 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/loongarch/crc-sext.c

diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
index 4ded1b3a117..525e1e82183 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -4264,6 +4264,17 @@ (define_insn "loongarch_<crc>_w_<size>_w"
   [(set_attr "type" "unknown")
    (set_attr "mode" "<MODE>")])
 
+(define_insn "loongarch_<crc>_w_<size>_w_extended"
+  [(set (match_operand:DI 0 "register_operand" "=r")
+	(sign_extend:DI
+	  (unspec:SI [(match_operand:QHSD 1 "register_operand" "r")
+		      (match_operand:SI 2 "register_operand" "r")]
+		     CRC)))]
+  "TARGET_64BIT"
+  "<crc>.w.<size>.w\t%0,%1,%2"
+  [(set_attr "type" "unknown")
+   (set_attr "mode" "<MODE>")])
+
 ;; With normal or medium code models, if the only use of a pc-relative
 ;; address is for loading or storing a value, then relying on linker
 ;; relaxation is not better than emitting the machine instruction directly.
diff --git a/gcc/testsuite/gcc.target/loongarch/crc-sext.c b/gcc/testsuite/gcc.target/loongarch/crc-sext.c
new file mode 100644
index 00000000000..9ade5a8e4ca
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/crc-sext.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=loongarch64" } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+/*
+**my_crc:
+**	crc.w.d.w	\$r4,\$r4,\$r5
+**	jr	\$r1
+*/
+int my_crc(long long dword, int crc)
+{
+	return __builtin_loongarch_crc_w_d_w(dword, crc);
+}
-- 
2.44.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] LoongArch: NFC: Deduplicate crc instruction defines
  2024-02-26  4:28 [PATCH 1/2] LoongArch: NFC: Deduplicate crc instruction defines Xi Ruoyao
  2024-02-26  4:28 ` [PATCH 2/2] LoongArch: Remove unneeded sign extension after crc/crcc instructions Xi Ruoyao
@ 2024-02-26 10:07 ` chenglulu
  1 sibling, 0 replies; 3+ messages in thread
From: chenglulu @ 2024-02-26 10:07 UTC (permalink / raw)
  To: Xi Ruoyao, gcc-patches; +Cc: i, xuchenghua

LGTM!

Thanks!

在 2024/2/26 下午12:28, Xi Ruoyao 写道:
> Introduce an iterator for UNSPEC_CRC and UNSPEC_CRCC to make the next
> change easier.
>
> gcc/ChangeLog:
>
> 	* config/loongarch/loongarch.md (CRC): New define_int_iterator.
> 	(crc): New define_int_attr.
> 	(loongarch_crc_w_<size>_w, loongarch_crcc_w_<size>_w): Unify
> 	into ...
> 	(loongarch_<crc>_w_<size>_w): ... here.
> ---
>   gcc/config/loongarch/loongarch.md | 18 +++++-------------
>   1 file changed, 5 insertions(+), 13 deletions(-)
>
> diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
> index 2ce7a151880..4ded1b3a117 100644
> --- a/gcc/config/loongarch/loongarch.md
> +++ b/gcc/config/loongarch/loongarch.md
> @@ -4251,24 +4251,16 @@ (define_peephole2
>   
>   
>   (define_mode_iterator QHSD [QI HI SI DI])
> +(define_int_iterator CRC [UNSPEC_CRC UNSPEC_CRCC])
> +(define_int_attr crc [(UNSPEC_CRC "crc") (UNSPEC_CRCC "crcc")])
>   
> -(define_insn "loongarch_crc_w_<size>_w"
> +(define_insn "loongarch_<crc>_w_<size>_w"
>     [(set (match_operand:SI 0 "register_operand" "=r")
>   	(unspec:SI [(match_operand:QHSD 1 "register_operand" "r")
>   		   (match_operand:SI 2 "register_operand" "r")]
> -		     UNSPEC_CRC))]
> +		     CRC))]
>     ""
> -  "crc.w.<size>.w\t%0,%1,%2"
> -  [(set_attr "type" "unknown")
> -   (set_attr "mode" "<MODE>")])
> -
> -(define_insn "loongarch_crcc_w_<size>_w"
> -  [(set (match_operand:SI 0 "register_operand" "=r")
> -	(unspec:SI [(match_operand:QHSD 1 "register_operand" "r")
> -		   (match_operand:SI 2 "register_operand" "r")]
> -		     UNSPEC_CRCC))]
> -  ""
> -  "crcc.w.<size>.w\t%0,%1,%2"
> +  "<crc>.w.<size>.w\t%0,%1,%2"
>     [(set_attr "type" "unknown")
>      (set_attr "mode" "<MODE>")])
>   


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-26 10:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-26  4:28 [PATCH 1/2] LoongArch: NFC: Deduplicate crc instruction defines Xi Ruoyao
2024-02-26  4:28 ` [PATCH 2/2] LoongArch: Remove unneeded sign extension after crc/crcc instructions Xi Ruoyao
2024-02-26 10:07 ` [PATCH 1/2] LoongArch: NFC: Deduplicate crc instruction defines chenglulu

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).