public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v2] LoongArch: Implement C[LT]Z_DEFINED_VALUE_AT_ZERO
@ 2023-11-17  2:38 Li Wei
  2023-11-17  8:40 ` [pushed][PATCH " chenglulu
  0 siblings, 1 reply; 2+ messages in thread
From: Li Wei @ 2023-11-17  2:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: xry111, i, xuchenghua, chenglulu, Li Wei

The LoongArch has defined ctz and clz on the backend, but if we want GCC
do CTZ transformation optimization in forwprop2 pass, GCC need to know
the value of c[lt]z at zero, which may be beneficial for some test cases
(like spec2017 deepsjeng_r).

After implementing the macro, we test dynamic instruction count on
deepsjeng_r:
- before 1688423249186
- after  1660311215745 (1.66% reduction)

gcc/ChangeLog:

	* config/loongarch/loongarch.h (CLZ_DEFINED_VALUE_AT_ZERO):
	  Implement.
	(CTZ_DEFINED_VALUE_AT_ZERO): Same.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr90838.c: add clz/ctz test support on LoongArch.
---
 gcc/config/loongarch/loongarch.h | 5 +++++
 gcc/testsuite/gcc.dg/pr90838.c   | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/gcc/config/loongarch/loongarch.h b/gcc/config/loongarch/loongarch.h
index ddac8e98ea9..115222e70fd 100644
--- a/gcc/config/loongarch/loongarch.h
+++ b/gcc/config/loongarch/loongarch.h
@@ -1239,3 +1239,8 @@ struct GTY (()) machine_function
 
 #define TARGET_EXPLICIT_RELOCS \
   (la_opt_explicit_relocs == EXPLICIT_RELOCS_ALWAYS)
+
+#define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
+  ((VALUE) = GET_MODE_UNIT_BITSIZE (MODE), 2)
+#define CTZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
+  ((VALUE) = GET_MODE_UNIT_BITSIZE (MODE), 2)
diff --git a/gcc/testsuite/gcc.dg/pr90838.c b/gcc/testsuite/gcc.dg/pr90838.c
index 759059683a9..40aad70499d 100644
--- a/gcc/testsuite/gcc.dg/pr90838.c
+++ b/gcc/testsuite/gcc.dg/pr90838.c
@@ -83,3 +83,8 @@ int ctz4 (unsigned long x)
 /* { dg-final { scan-assembler-times "ctz\t" 3 { target { rv32 } } } } */
 /* { dg-final { scan-assembler-times "andi\t" 1 { target { rv32 } } } } */
 /* { dg-final { scan-assembler-times "mul\t" 1 { target { rv32 } } } } */
+
+/* { dg-final { scan-tree-dump-times {= \.CTZ} 4 "forwprop2" { target { loongarch64*-*-* } } } } */
+/* { dg-final { scan-assembler-times "ctz.d\t" 1 { target { loongarch64*-*-* } } } } */
+/* { dg-final { scan-assembler-times "ctz.w\t" 3 { target { loongarch64*-*-* } } } } */
+/* { dg-final { scan-assembler-times "andi\t" 4 { target { loongarch64*-*-* } } } } */
-- 
2.31.1


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

* Re: [pushed][PATCH v2] LoongArch: Implement C[LT]Z_DEFINED_VALUE_AT_ZERO
  2023-11-17  2:38 [PATCH v2] LoongArch: Implement C[LT]Z_DEFINED_VALUE_AT_ZERO Li Wei
@ 2023-11-17  8:40 ` chenglulu
  0 siblings, 0 replies; 2+ messages in thread
From: chenglulu @ 2023-11-17  8:40 UTC (permalink / raw)
  To: Li Wei, gcc-patches; +Cc: xry111, i, xuchenghua

Pushed to r14-5547.

在 2023/11/17 上午10:38, Li Wei 写道:
> The LoongArch has defined ctz and clz on the backend, but if we want GCC
> do CTZ transformation optimization in forwprop2 pass, GCC need to know
> the value of c[lt]z at zero, which may be beneficial for some test cases
> (like spec2017 deepsjeng_r).
>
> After implementing the macro, we test dynamic instruction count on
> deepsjeng_r:
> - before 1688423249186
> - after  1660311215745 (1.66% reduction)
>
> gcc/ChangeLog:
>
> 	* config/loongarch/loongarch.h (CLZ_DEFINED_VALUE_AT_ZERO):
> 	  Implement.
> 	(CTZ_DEFINED_VALUE_AT_ZERO): Same.
>
> gcc/testsuite/ChangeLog:
>
> 	* gcc.dg/pr90838.c: add clz/ctz test support on LoongArch.
> ---
>   gcc/config/loongarch/loongarch.h | 5 +++++
>   gcc/testsuite/gcc.dg/pr90838.c   | 5 +++++
>   2 files changed, 10 insertions(+)
>
> diff --git a/gcc/config/loongarch/loongarch.h b/gcc/config/loongarch/loongarch.h
> index ddac8e98ea9..115222e70fd 100644
> --- a/gcc/config/loongarch/loongarch.h
> +++ b/gcc/config/loongarch/loongarch.h
> @@ -1239,3 +1239,8 @@ struct GTY (()) machine_function
>   
>   #define TARGET_EXPLICIT_RELOCS \
>     (la_opt_explicit_relocs == EXPLICIT_RELOCS_ALWAYS)
> +
> +#define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
> +  ((VALUE) = GET_MODE_UNIT_BITSIZE (MODE), 2)
> +#define CTZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
> +  ((VALUE) = GET_MODE_UNIT_BITSIZE (MODE), 2)
> diff --git a/gcc/testsuite/gcc.dg/pr90838.c b/gcc/testsuite/gcc.dg/pr90838.c
> index 759059683a9..40aad70499d 100644
> --- a/gcc/testsuite/gcc.dg/pr90838.c
> +++ b/gcc/testsuite/gcc.dg/pr90838.c
> @@ -83,3 +83,8 @@ int ctz4 (unsigned long x)
>   /* { dg-final { scan-assembler-times "ctz\t" 3 { target { rv32 } } } } */
>   /* { dg-final { scan-assembler-times "andi\t" 1 { target { rv32 } } } } */
>   /* { dg-final { scan-assembler-times "mul\t" 1 { target { rv32 } } } } */
> +
> +/* { dg-final { scan-tree-dump-times {= \.CTZ} 4 "forwprop2" { target { loongarch64*-*-* } } } } */
> +/* { dg-final { scan-assembler-times "ctz.d\t" 1 { target { loongarch64*-*-* } } } } */
> +/* { dg-final { scan-assembler-times "ctz.w\t" 3 { target { loongarch64*-*-* } } } } */
> +/* { dg-final { scan-assembler-times "andi\t" 4 { target { loongarch64*-*-* } } } } */


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

end of thread, other threads:[~2023-11-17  8:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-17  2:38 [PATCH v2] LoongArch: Implement C[LT]Z_DEFINED_VALUE_AT_ZERO Li Wei
2023-11-17  8:40 ` [pushed][PATCH " 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).