From: Qing Zhao Date: Fri, 27 Jul 2018 01:56:57 +0000 (+0000) Subject: Disable strcmp/strncmp/memcmp inlining when optimization X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3d592d2d56ccd3298ea0121de16615d27b9fb659;p=gcc.git Disable strcmp/strncmp/memcmp inlining when optimization level is lower than 2 or Os From-SVN: r263028 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f5e8d62c7b9..c2bf139a659 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-07-26 Qing Zhao + + * builtins.c (inline_expand_builtin_string_cmp): Disable inlining + when optimization level is lower than 2 or optimize for size. + 2018-07-26 Martin Sebor PR tree-optimization/86043 diff --git a/gcc/builtins.c b/gcc/builtins.c index aa3e0d80cd1..c6596113801 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -6854,6 +6854,11 @@ 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 when optimizing for size or + optimization level below 2. */ + if (optimize < 2 || optimize_insn_for_size_p ()) + return NULL_RTX; + gcc_checking_assert (fcode == BUILT_IN_STRCMP || fcode == BUILT_IN_STRNCMP || fcode == BUILT_IN_MEMCMP); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index eccfcd0caec..f48c3d3454d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-07-26 Qing Zhao + + * gcc.dg/strcmpopt_5.c: Change to O2 to enable the transformation. + * gcc.dg/strcmpopt_6.c: Likewise. + 2018-07-26 Pat Haugen PR target/86612 diff --git a/gcc/testsuite/gcc.dg/strcmpopt_5.c b/gcc/testsuite/gcc.dg/strcmpopt_5.c index c30fb78eb64..d368277bfbb 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 0f8cf87fbd0..964b9e4839f 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" } } */