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

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