public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][Middle-end] disable strcmp/strncmp inlining with O2 below and Os
@ 2018-07-25 17:08 Qing Zhao
  2018-07-26  8:26 ` Richard Biener
  2018-07-30 13:45 ` Christophe Lyon
  0 siblings, 2 replies; 6+ messages in thread
From: Qing Zhao @ 2018-07-25 17:08 UTC (permalink / raw)
  To: gcc Patches; +Cc: jakub Jelinek, jeff Law, richard Biener, Wilco Dijkstra

[-- Attachment #1: Type: text/plain, Size: 647 bytes --]

Hi,

As Wilco suggested, the new added strcmp/strncmp inlining should be only enabled with O2 and above.

this is the simple patch for this change.

tested on both X86 and aarch64.

Okay for thunk?

Qing

gcc/ChangeLog:

+2018-07-25  Qing Zhao  <qing.zhao@oracle.com>
+
+       * builtins.c (inline_expand_builtin_string_cmp): Disable inlining
+       when optimization level is lower than 2 or optimize for size.
+       

gcc/testsuite/ChangeLog:

+2018-07-25  Qing Zhao  <qing.zhao@oracle.com>
+
+       * gcc.dg/strcmpopt_5.c: Change to O2 to enable the transformation.
+       * gcc.dg/strcmpopt_6.c: Likewise.
+


[-- Attachment #2: 78809_O2.patch --]
[-- Type: application/octet-stream, Size: 2217 bytes --]

From ebaf918952f6bd805537516832ac9de6054be884 Mon Sep 17 00:00:00 2001
From: qing zhao <qing.zhao@oracle.com>
Date: Tue, 24 Jul 2018 07:27:02 -0700
Subject: [PATCH] Disable strcmp/strncmp/memcmp inlining when optimization
 level is lower than 2 or Os

---
 gcc/builtins.c                     | 4 ++++
 gcc/testsuite/gcc.dg/strcmpopt_5.c | 2 +-
 gcc/testsuite/gcc.dg/strcmpopt_6.c | 4 ++--
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 539a6d1..68b5b62 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -6840,6 +6840,10 @@ inline_expand_builtin_string_cmp (tree exp, rtx target)
   unsigned HOST_WIDE_INT length = 0;
   bool is_ncmp = (fcode == BUILT_IN_STRNCMP || fcode == BUILT_IN_MEMCMP);
 
+  /* Do NOT apply this inlining expansion with O2 below and Os.  */
+  if (optimize < 2 || optimize_size)
+    return NULL_RTX;
+
   gcc_checking_assert (fcode == BUILT_IN_STRCMP
 		       || fcode == BUILT_IN_STRNCMP
 		       || fcode == BUILT_IN_MEMCMP);
diff --git a/gcc/testsuite/gcc.dg/strcmpopt_5.c b/gcc/testsuite/gcc.dg/strcmpopt_5.c
index c30fb78..d368277 100644
--- a/gcc/testsuite/gcc.dg/strcmpopt_5.c
+++ b/gcc/testsuite/gcc.dg/strcmpopt_5.c
@@ -1,5 +1,5 @@
 /* { dg-do run } */
-/* { dg-options "-O -fdump-rtl-expand" } */
+/* { dg-options "-O2 -fdump-rtl-expand" } */
 
 typedef struct { char s[8]; int x; } S;
 __attribute__ ((noinline)) int
diff --git a/gcc/testsuite/gcc.dg/strcmpopt_6.c b/gcc/testsuite/gcc.dg/strcmpopt_6.c
index 0f8cf87..964b9e4 100644
--- a/gcc/testsuite/gcc.dg/strcmpopt_6.c
+++ b/gcc/testsuite/gcc.dg/strcmpopt_6.c
@@ -1,7 +1,7 @@
 /* When the specified length exceeds one of the arguments of the call to memcmp, 
    the call to memcmp should NOT be inlined.  */
 /* { dg-do run } */
-/* { dg-options "-O -fdump-rtl-expand -Wno-stringop-overflow" } */
+/* { dg-options "-O2 -fdump-rtl-expand -Wno-stringop-overflow" } */
 
 typedef struct { char s[8]; int x; } S;
 
@@ -33,4 +33,4 @@ int main (void)
 
 }
 
-/* { dg-final { scan-rtl-dump-times "__builtin_memcmp" 4 "expand" } } */
+/* { dg-final { scan-rtl-dump-times "__builtin_memcmp" 6 "expand" } } */
-- 
1.9.1

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

* Re: [PATCH][Middle-end] disable strcmp/strncmp inlining with O2 below and Os
  2018-07-25 17:08 [PATCH][Middle-end] disable strcmp/strncmp inlining with O2 below and Os Qing Zhao
@ 2018-07-26  8:26 ` Richard Biener
  2018-07-26 15:00   ` Qing Zhao
  2018-07-30 13:45 ` Christophe Lyon
  1 sibling, 1 reply; 6+ messages in thread
From: Richard Biener @ 2018-07-26  8:26 UTC (permalink / raw)
  To: Qing Zhao; +Cc: gcc Patches, jakub Jelinek, jeff Law, Wilco Dijkstra

On Wed, 25 Jul 2018, Qing Zhao wrote:

> Hi,
> 
> As Wilco suggested, the new added strcmp/strncmp inlining should be only enabled with O2 and above.
> 
> this is the simple patch for this change.
> 
> tested on both X86 and aarch64.
> 
> Okay for thunk?

You should simply use

  if (optimize_insn_for_size_p ())
    return NULL_RTX;

to be properly profile-aware.  OK with that change.

Richard.

> Qing
> 
> gcc/ChangeLog:
> 
> +2018-07-25  Qing Zhao  <qing.zhao@oracle.com>
> +
> +       * builtins.c (inline_expand_builtin_string_cmp): Disable inlining
> +       when optimization level is lower than 2 or optimize for size.
> +       
> 
> gcc/testsuite/ChangeLog:
> 
> +2018-07-25  Qing Zhao  <qing.zhao@oracle.com>
> +
> +       * gcc.dg/strcmpopt_5.c: Change to O2 to enable the transformation.
> +       * gcc.dg/strcmpopt_6.c: Likewise.
> +
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)

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

* Re: [PATCH][Middle-end] disable strcmp/strncmp inlining with O2 below and Os
  2018-07-26  8:26 ` Richard Biener
@ 2018-07-26 15:00   ` Qing Zhao
  0 siblings, 0 replies; 6+ messages in thread
From: Qing Zhao @ 2018-07-26 15:00 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc Patches, jakub Jelinek, jeff Law, Wilco Dijkstra


> On Jul 26, 2018, at 3:26 AM, Richard Biener <rguenther@suse.de> wrote:
> 
> On Wed, 25 Jul 2018, Qing Zhao wrote:
> 
>> Hi,
>> 
>> As Wilco suggested, the new added strcmp/strncmp inlining should be only enabled with O2 and above.
>> 
>> this is the simple patch for this change.
>> 
>> tested on both X86 and aarch64.
>> 
>> Okay for thunk?
> 
> You should simply use
> 
>  if (optimize_insn_for_size_p ())
>    return NULL_RTX;
> 
> to be properly profile-aware.  OK with that change.

thanks for the review.

I will make the change, retest it, and then commit it.

Qing
> 
> Richard.
> 

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

* Re: [PATCH][Middle-end] disable strcmp/strncmp inlining with O2 below and Os
  2018-07-25 17:08 [PATCH][Middle-end] disable strcmp/strncmp inlining with O2 below and Os Qing Zhao
  2018-07-26  8:26 ` Richard Biener
@ 2018-07-30 13:45 ` Christophe Lyon
  2018-08-06 18:47   ` Qing Zhao
  2018-08-07 17:03   ` Qing Zhao
  1 sibling, 2 replies; 6+ messages in thread
From: Christophe Lyon @ 2018-07-30 13:45 UTC (permalink / raw)
  To: qing.zhao
  Cc: gcc Patches, Jakub Jelinek, Jeff Law, Richard Biener, Wilco Dijkstra

On Wed, 25 Jul 2018 at 19:08, Qing Zhao <qing.zhao@oracle.com> wrote:
>
> Hi,
>
> As Wilco suggested, the new added strcmp/strncmp inlining should be only enabled with O2 and above.
>
> this is the simple patch for this change.
>
> tested on both X86 and aarch64.
>
> Okay for thunk?
>
> Qing
>
> gcc/ChangeLog:
>
> +2018-07-25  Qing Zhao  <qing.zhao@oracle.com>
> +
> +       * builtins.c (inline_expand_builtin_string_cmp): Disable inlining
> +       when optimization level is lower than 2 or optimize for size.
> +
>
> gcc/testsuite/ChangeLog:
>
> +2018-07-25  Qing Zhao  <qing.zhao@oracle.com>
> +
> +       * gcc.dg/strcmpopt_5.c: Change to O2 to enable the transformation.
> +       * gcc.dg/strcmpopt_6.c: Likewise.
> +
>

Hi,

After this change, I've noticed that:
FAIL: gcc.dg/strcmpopt_6.c scan-rtl-dump-times expand "__builtin_memcmp" 6
on arm-none-linux-gnueabi
--with-mode thumb
--with-cpu cortex-a9
and forcing -march=armv5t via RUNTESTFLAGS

The log says:
gcc.dg/strcmpopt_6.c: pattern found 4 times
FAIL: gcc.dg/strcmpopt_6.c scan-rtl-dump-times expand "__builtin_memcmp" 6

Christophe

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

* Re: [PATCH][Middle-end] disable strcmp/strncmp inlining with O2 below and Os
  2018-07-30 13:45 ` Christophe Lyon
@ 2018-08-06 18:47   ` Qing Zhao
  2018-08-07 17:03   ` Qing Zhao
  1 sibling, 0 replies; 6+ messages in thread
From: Qing Zhao @ 2018-08-06 18:47 UTC (permalink / raw)
  To: Christophe Lyon; +Cc: gcc Patches

thanks for reporting this issue.

I will take a look.

Qing
> On Jul 30, 2018, at 8:45 AM, Christophe Lyon <christophe.lyon@linaro.org> wrote:
> 
> On Wed, 25 Jul 2018 at 19:08, Qing Zhao <qing.zhao@oracle.com <mailto:qing.zhao@oracle.com>> wrote:
>> 
>> Hi,
>> 
>> As Wilco suggested, the new added strcmp/strncmp inlining should be only enabled with O2 and above.
>> 
>> this is the simple patch for this change.
>> 
>> tested on both X86 and aarch64.
>> 
>> Okay for thunk?
>> 
>> Qing
>> 
>> gcc/ChangeLog:
>> 
>> +2018-07-25  Qing Zhao  <qing.zhao@oracle.com>
>> +
>> +       * builtins.c (inline_expand_builtin_string_cmp): Disable inlining
>> +       when optimization level is lower than 2 or optimize for size.
>> +
>> 
>> gcc/testsuite/ChangeLog:
>> 
>> +2018-07-25  Qing Zhao  <qing.zhao@oracle.com>
>> +
>> +       * gcc.dg/strcmpopt_5.c: Change to O2 to enable the transformation.
>> +       * gcc.dg/strcmpopt_6.c: Likewise.
>> +
>> 
> 
> Hi,
> 
> After this change, I've noticed that:
> FAIL: gcc.dg/strcmpopt_6.c scan-rtl-dump-times expand "__builtin_memcmp" 6
> on arm-none-linux-gnueabi
> --with-mode thumb
> --with-cpu cortex-a9
> and forcing -march=armv5t via RUNTESTFLAGS
> 
> The log says:
> gcc.dg/strcmpopt_6.c: pattern found 4 times
> FAIL: gcc.dg/strcmpopt_6.c scan-rtl-dump-times expand "__builtin_memcmp" 6
> 
> Christophe

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

* Re: [PATCH][Middle-end] disable strcmp/strncmp inlining with O2 below and Os
  2018-07-30 13:45 ` Christophe Lyon
  2018-08-06 18:47   ` Qing Zhao
@ 2018-08-07 17:03   ` Qing Zhao
  1 sibling, 0 replies; 6+ messages in thread
From: Qing Zhao @ 2018-08-07 17:03 UTC (permalink / raw)
  To: Christophe Lyon; +Cc: gcc Patches

Hi, Christophe,

I have attached a patch in PR86519, could you please download it and test it, and let me know the result.

thanks.

Qing
> On Jul 30, 2018, at 8:45 AM, Christophe Lyon <christophe.lyon@linaro.org> wrote:
> 
> On Wed, 25 Jul 2018 at 19:08, Qing Zhao <qing.zhao@oracle.com <mailto:qing.zhao@oracle.com>> wrote:
>> 
>> Hi,
>> 
>> As Wilco suggested, the new added strcmp/strncmp inlining should be only enabled with O2 and above.
>> 
>> this is the simple patch for this change.
>> 
>> tested on both X86 and aarch64.
>> 
>> Okay for thunk?
>> 
>> Qing
>> 
>> gcc/ChangeLog:
>> 
>> +2018-07-25  Qing Zhao  <qing.zhao@oracle.com>
>> +
>> +       * builtins.c (inline_expand_builtin_string_cmp): Disable inlining
>> +       when optimization level is lower than 2 or optimize for size.
>> +
>> 
>> gcc/testsuite/ChangeLog:
>> 
>> +2018-07-25  Qing Zhao  <qing.zhao@oracle.com>
>> +
>> +       * gcc.dg/strcmpopt_5.c: Change to O2 to enable the transformation.
>> +       * gcc.dg/strcmpopt_6.c: Likewise.
>> +
>> 
> 
> Hi,
> 
> After this change, I've noticed that:
> FAIL: gcc.dg/strcmpopt_6.c scan-rtl-dump-times expand "__builtin_memcmp" 6
> on arm-none-linux-gnueabi
> --with-mode thumb
> --with-cpu cortex-a9
> and forcing -march=armv5t via RUNTESTFLAGS
> 
> The log says:
> gcc.dg/strcmpopt_6.c: pattern found 4 times
> FAIL: gcc.dg/strcmpopt_6.c scan-rtl-dump-times expand "__builtin_memcmp" 6
> 
> Christophe

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

end of thread, other threads:[~2018-08-07 17:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-25 17:08 [PATCH][Middle-end] disable strcmp/strncmp inlining with O2 below and Os Qing Zhao
2018-07-26  8:26 ` Richard Biener
2018-07-26 15:00   ` Qing Zhao
2018-07-30 13:45 ` Christophe Lyon
2018-08-06 18:47   ` Qing Zhao
2018-08-07 17:03   ` Qing Zhao

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