public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, rs6000] Call library for block memory compare when optimizing for size
@ 2023-12-20  8:56 HAO CHEN GUI
  2023-12-21  6:23 ` Kewen.Lin
  0 siblings, 1 reply; 2+ messages in thread
From: HAO CHEN GUI @ 2023-12-20  8:56 UTC (permalink / raw)
  To: gcc-patches; +Cc: Segher Boessenkool, David, Kewen.Lin, Peter Bergner

Hi,
  This patch call library function for block memory compare when it's
optimized for size.

  Bootstrapped and tested on x86 and powerpc64-linux BE and LE with no
regressions. Is this OK for trunk?

Thanks
Gui Haochen

ChangeLog
rs6000: Call library for block memory compare when optimizing for size

gcc/
	* config/rs6000/rs6000-string.cc (expand_block_compare): Return
	false when optimizing for size.

gcc/testsuite/
	* gcc.target/powerpc/block-cm-3.c: New.

patch.diff
diff --git a/gcc/config/rs6000/rs6000-string.cc b/gcc/config/rs6000/rs6000-string.cc
index 05dc41622f4..5149273b80e 100644
--- a/gcc/config/rs6000/rs6000-string.cc
+++ b/gcc/config/rs6000/rs6000-string.cc
@@ -1947,6 +1947,9 @@ expand_block_compare_gpr(unsigned HOST_WIDE_INT bytes, unsigned int base_align,
 bool
 expand_block_compare (rtx operands[])
 {
+  if (optimize_insn_for_size_p ())
+    return false;
+
   rtx target = operands[0];
   rtx orig_src1 = operands[1];
   rtx orig_src2 = operands[2];
diff --git a/gcc/testsuite/gcc.target/powerpc/block-cmp-3.c b/gcc/testsuite/gcc.target/powerpc/block-cmp-3.c
new file mode 100644
index 00000000000..c7e853ad593
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/block-cmp-3.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-Os" } */
+/* { dg-final { scan-assembler-times {\mb[l]? memcmp\M} 1 } }  */
+
+int foo (const char* s1, const char* s2)
+{
+  return __builtin_memcmp (s1, s2, 4);
+}


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

* Re: [Patch, rs6000] Call library for block memory compare when optimizing for size
  2023-12-20  8:56 [Patch, rs6000] Call library for block memory compare when optimizing for size HAO CHEN GUI
@ 2023-12-21  6:23 ` Kewen.Lin
  0 siblings, 0 replies; 2+ messages in thread
From: Kewen.Lin @ 2023-12-21  6:23 UTC (permalink / raw)
  To: HAO CHEN GUI; +Cc: Segher Boessenkool, David, Peter Bergner, gcc-patches

Hi Haochen,

on 2023/12/20 16:56, HAO CHEN GUI wrote:
> Hi,
>   This patch call library function for block memory compare when it's
> optimized for size.
> 
>   Bootstrapped and tested on x86 and powerpc64-linux BE and LE with no
> regressions. Is this OK for trunk?
> 
> Thanks
> Gui Haochen
> 
> ChangeLog
> rs6000: Call library for block memory compare when optimizing for size
> 
> gcc/
> 	* config/rs6000/rs6000-string.cc (expand_block_compare): Return
> 	false when optimizing for size.
> 
> gcc/testsuite/
> 	* gcc.target/powerpc/block-cm-3.c: New.

Nit: s/cm/cmp/

> 
> patch.diff
> diff --git a/gcc/config/rs6000/rs6000-string.cc b/gcc/config/rs6000/rs6000-string.cc
> index 05dc41622f4..5149273b80e 100644
> --- a/gcc/config/rs6000/rs6000-string.cc
> +++ b/gcc/config/rs6000/rs6000-string.cc
> @@ -1947,6 +1947,9 @@ expand_block_compare_gpr(unsigned HOST_WIDE_INT bytes, unsigned int base_align,
>  bool
>  expand_block_compare (rtx operands[])
>  {
> +  if (optimize_insn_for_size_p ())
> +    return false;

Thanks for separating this out.  I just noticed that for expander
cmpstrnsi and cmpstrsi, we put this check in the associated {} code,
since it doesn't need extra checks here, I'd prefer to move this
check to cmpmemsi to keep consistent with the existing ones.

OK for trunk with this move (also tested well), thanks!

BR,
Kewen

> +
>    rtx target = operands[0];
>    rtx orig_src1 = operands[1];
>    rtx orig_src2 = operands[2];
> diff --git a/gcc/testsuite/gcc.target/powerpc/block-cmp-3.c b/gcc/testsuite/gcc.target/powerpc/block-cmp-3.c
> new file mode 100644
> index 00000000000..c7e853ad593
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/block-cmp-3.c
> @@ -0,0 +1,8 @@
> +/* { dg-do compile } */
> +/* { dg-options "-Os" } */
> +/* { dg-final { scan-assembler-times {\mb[l]? memcmp\M} 1 } }  */
> +
> +int foo (const char* s1, const char* s2)
> +{
> +  return __builtin_memcmp (s1, s2, 4);
> +}
> 


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

end of thread, other threads:[~2023-12-21  6:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-20  8:56 [Patch, rs6000] Call library for block memory compare when optimizing for size HAO CHEN GUI
2023-12-21  6:23 ` Kewen.Lin

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