This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH][Middle-end]3rd patch of PR78809


Hi,

this is the 3rd (and the last) patch for PR78809:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78809
Inline strcmp with small constant strings

The design doc for PR78809 is at:
https://www.mail-archive.com/gcc@gcc.gnu.org/msg83822.html

this patch is for the third part of change of PR78809.

C. for strcmp (s1, s2), strncmp (s1, s2, n), and memcmp (s1, s2, n)
   if the result is NOT used to do simple equality test against zero, one of
"s1" or "s2" is a small constant string, n is a constant, and the Min value of
the length of the constant string and "n" is smaller than a predefined
threshold T,
   inline the call by a byte-to-byte comparision sequence to avoid calling
overhead.

adding test case strcmpopt_5.c into gcc.dg for part C of PR78809.

bootstraped and tested on both X86 and Aarch64. no regression.

I have done some experiments to check the run-time performance impact 
and code-size impact from such inlining with different threshold for the
length of the constant string to inline, the data were recorded in the attachments of 
PR78809:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78809.

and finally decide that the default value of the threshold is 3. 
this value of the threshold can be adjusted by the new option:

--param builtin-string-cmp-inline-length=

The following is the patch.

thanks.

Qing

gcc/ChangeLog:

+2018-06-18  Qing Zhao  <qing.zhao@oracle.com>
+
+       PR middle-end/78809
+       * builtins.c (expand_builtin_memcmp): Inline the calls first
+       when result_eq is false.
+       (expand_builtin_strcmp): Inline the calls first.
+       (expand_builtin_strncmp): Likewise.
+       (inline_string_cmp): New routine. Expand a string compare 
+       call by using a sequence of char comparison.
+       (inline_expand_builtin_string_cmp): New routine. Inline expansion
+       a call to str(n)cmp/memcmp.
+       * doc/invoke.texi (--param builtin-string-cmp-inline-length): New option.
+       * params.def (BUILTIN_STRING_CMP_INLINE_LENGTH): New.
+

gcc/testsuite/ChangeLog:

+2018-06-18  Qing Zhao  <qing.zhao@oracle.com>
+
+       PR middle-end/78809
+       * gcc.dg/strcmpopt_5.c: New test.
+


Attachment: 0001-3nd-Patch-for-PR78009.patch
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]