diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2020-07-15 10:34:54 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2020-10-26 04:15:47 -0700 |
commit | 4052c05e5b30fee0fb95a51e74e12a56dce29491 (patch) | |
tree | b022dbf38ce2640fd94a6a90cc0afff50bf01280 /gcc | |
parent | 3edc21af5272194794fbf24b2c5f0981c632e866 (diff) | |
download | gcc-4052c05e5b30fee0fb95a51e74e12a56dce29491.zip gcc-4052c05e5b30fee0fb95a51e74e12a56dce29491.tar.gz gcc-4052c05e5b30fee0fb95a51e74e12a56dce29491.tar.bz2 |
x86: Inline strncmp only with -minline-all-stringops
Expand strncmp to "repz cmpsb" only with -minline-all-stringops since
"repz cmpsb" can be much slower than strncmp function implemented with
vector instructions, see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43052
gcc/
PR target/95458
* config/i386/i386-expand.c (ix86_expand_cmpstrn_or_cmpmem):
Return false for -mno-inline-all-stringops.
gcc/testsuite/
PR target/95458
* gcc.target/i386/pr95458-1.c: New test.
* gcc.target/i386/pr95458-2.c: Likewise.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/config/i386/i386-expand.c | 19 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/pr95458-1.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/pr95458-2.c | 7 |
3 files changed, 25 insertions, 12 deletions
diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c index bd83a8e..19a9f2d 100644 --- a/gcc/config/i386/i386-expand.c +++ b/gcc/config/i386/i386-expand.c @@ -7679,7 +7679,13 @@ bool ix86_expand_cmpstrn_or_cmpmem (rtx result, rtx src1, rtx src2, rtx length, rtx align, bool is_cmpstrn) { - if (optimize_insn_for_size_p () && !TARGET_INLINE_ALL_STRINGOPS) + /* Expand strncmp and memcmp only with -minline-all-stringops since + "repz cmpsb" can be much slower than strncmp and memcmp functions + implemented with vector instructions, see + + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43052 + */ + if (!TARGET_INLINE_ALL_STRINGOPS) return false; /* Can't use this if the user has appropriated ecx, esi or edi. */ @@ -7706,17 +7712,6 @@ ix86_expand_cmpstrn_or_cmpmem (rtx result, rtx src1, rtx src2, == STRING_CST)))) return false; } - else - { - /* Expand memcmp to "repz cmpsb" only for -minline-all-stringops - since "repz cmpsb" can be much slower than memcmp function - implemented with vector instructions, see - - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43052 - */ - if (!TARGET_INLINE_ALL_STRINGOPS) - return false; - } rtx addr1 = copy_addr_to_reg (XEXP (src1, 0)); rtx addr2 = copy_addr_to_reg (XEXP (src2, 0)); diff --git a/gcc/testsuite/gcc.target/i386/pr95458-1.c b/gcc/testsuite/gcc.target/i386/pr95458-1.c new file mode 100644 index 0000000..231a478 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr95458-1.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -minline-all-stringops" } */ + +int +func (char *d, unsigned int l) +{ + return __builtin_strncmp (d, "foo", l) ? 1 : 2; +} + +/* { dg-final { scan-assembler-not "call\[\\t \]*_?strncmp" } } */ +/* { dg-final { scan-assembler "cmpsb" } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr95458-2.c b/gcc/testsuite/gcc.target/i386/pr95458-2.c new file mode 100644 index 0000000..1a62044 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr95458-2.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mno-inline-all-stringops" } */ + +#include "pr95458-1.c" + +/* { dg-final { scan-assembler "call\[\\t \]*_?strncmp" } } */ +/* { dg-final { scan-assembler-not "cmpsb" } } */ |